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.

Jmol uses a Java List for its internal variable arrays, and when more room
is needed for those, it is added by increasing the array size by at least
1/2, with the starting size is 10.  So if you did this:

a = []
for (i = 1; i < 20000; i++) a.push(i)

the array would be copied about 20 times, I think.

Bob

ps -- Eric, this is fixed, and there is no longer any delay. I'll get you
that as a chemapps zip file.
------------------------------------------------------------------------------
_______________________________________________
Jmol-users mailing list
Jmol-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-users

Reply via email to