views:

25

answers:

1

Hi,

I'm building a tool in flash to tell me how long it takes to load a bit of content off of a server. I'm doing

foo = new Date().getTime();
// get the thing
bar = new Date().getTime();
trace(bar-foo);

Yet, somehow, the times just seem to fluctuate HUGELY, from 3ms to 150ms. When I test this using Python, the times are consistently around 5ms. Does anyone know what's going on, and how I fix it?!

Thanks very much!

A: 

that is due to flash players asynchronous execution model. the load operation happens at some point in time in the background.

so while in python you would naturally do something synchronous like:

var foo = now();
var data = loadData();
var bar = now();

in AS3 this is more like:

var foo = now();
ioThread.addJob(loadData, function (data) { var bar = now() });

or even, in a browser, io jobs are carried out by the browser. But in any case, it happens quite lazily, probably based on the assumption that bandwidth is the expected bottleneck.

greetz
back2dos

back2dos