On 12/17/2015 04:18 PM, Robert Hanson wrote: > On Thu, Dec 17, 2015 at 8:30 AM, Rolf Huehne <rhue...@leibniz-fli.de> wrote: > >> On 12/17/2015 04:39 AM, Robert Hanson wrote: >>> Wow, what a GREAT FIND, Eric! Say you have a set of information in the >> form >>> of an array for n items. Now you need to set the value for n+1. Well, of >>> course you were efficient in your creating an array of just n values, so >>> now you have to create a NEW array that is n+1 long instead of n long. >>> That's pretty fast, if you do it once. But now do this: >>> >>> a = []; >>> for (i = 0; i < 20000; i++) { >>> if (a.length < i + 1) >>> a = copyArray(a, i + 1); >>> } >>> >>> See the problem? Not only are you creating an array that is 20000 long, >> you >>> are creating a new array from an old one *20000 times. *Ouch! >>> >> Bob, I also tried to avoid this in Jmol scripting by setting the last >> value of an array first: >> >> var parsedData = []; >> parsedData[tsvData.size] = 0; >> >> Would you confirm that this will actually work? >> >> > When I tried this: > > t = now() > a = [] > a[20000] = 0 > for (i = 1; i < 20000; i++) a.push(i) > print now(t) > > t = now() > a = [] > for (i = 1; i < 20000; i++) a.push(i) > print now(t) > > I found the first was about 5% faster than the second in both Java and > HTML5. You could experiment yourself with that. > I got mixed results:
In Java the first one was much slower than the second one (210,142) in the first run. In subsequent runs the times were more similar (72,71; 69,75; 69,70; 69,70). In HTML5 the second one was always slightly faster (3277,3177; 3248,3136; 3164,3146; 3632,3543; 3565,3419). Regards, Rolf -- Rolf Huehne Postdoc Leibniz Institute on Aging - Fritz Lipmann Institute (FLI) Beutenbergstrasse 11 07745 Jena, Germany Phone: +49 3641 65 6205 Fax: +49 3641 65 6210 E-Mail: rhue...@leibniz-fli.de Website: http://www.leibniz-fli.de Scientific Director: Prof. Dr. K. Lenhard Rudolph Head of Administration: Dr. Daniele Barthel Chairman of Board of Trustees: Burkhard Zinner VAT No: DE 153 925 464 Register of Associations: No. 230296, Amtsgericht Jena Tax Number: 162/141/08228 ------------------------------------------------------------------------------ _______________________________________________ Jmol-users mailing list Jmol-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jmol-users