well, we all know that some actions can be performed
this way or another, faster or slower. but, some actions
must be fast, couse it might be whole movie is awaiting
for it, for example - loading external data. sometime
it is not so important, because 5ms or 20ms will not be
noticeable, but sometime it is very important, because
some function may miss parameters and movie can stuck.
so, I was looking in
: gsb's code : for loading data into
array from external text file. nice example for test.
here is the part of original code which should be optimized:
var p=s.split("\n"), q;
for(var i=0,k=-1;i
if((q=p[i].trim())!="") {
if(typeOf(fieldSeperator)!="string") this.data[++k]=q;
else {
s=q.split(fieldSeperator.charAt(0));
this.data[++k]=new Array();
for(var j=0;j
}
}
}
and here is optimized code:
var p=(s.split(" ").join("")).split("\r\n");
if(fieldSeperator!=undefined) for (i in p)p[i]=p[i].split(fieldSeperator);
this.data.datas=p;
it is not only shortest code, it is faster one. how much faster ?
in my tests, when converts string to 1D array it is faster twice and little
bit more, when converts string to 2D array it is faster 4 to 6 times,
depends on datas. and to avoid missunderstandings, both of codes
produces exactly the same final results.
tested with mm flash player 7, win XP SP2, smax 2004.09.10
so, to remind you, sometime, in some actions time is important
and loading/pushing data is one of the most critical moments.
you can downolad test files from
DOWNLOAD SECTION extract files to some
folder than test gsbGetData.swi and cbxGetData.swi . Both of them
will use for test file: datas.txt which contains 100 lines of datas.
note: test must be done in external browser.