(but my results with this using slice() was about the same with Firefox. n=1000000; a = new Array(n); for (var i = a.length;--i >= 0;) {a[i] = i;} t1=performance.now(); b = a.slice(); t2=performance.now(); c = new Array(n); for (var i = a.length;--i >= 0;) { c[i] = a[i] } t3=performance.now(); dt1= t2 - t1; dt2= t3 - t2; a[5] =-5; msg='slice: ' + dt1 + 'ms copy: ' + dt2 + 'ms a[5]=' + a[5] + 'b[5]=' + b[5] + ' c[5]=' + c[5]; alert(msg)
On Fri, Dec 18, 2015 at 3:00 PM, Robert Hanson <hans...@stolaf.edu> wrote: > I'm not sure the Java data are significant -- all you are seeing there is > the overhead for executing JavaScript from Java. The Java itself has > nothing to do with it, since the loop is in JavaScript. > > Note that you need to use .slice() not .slice(0). The latter just pulls > the first value out. > > On Fri, Dec 18, 2015 at 2:43 PM, Rolf Huehne <rhue...@leibniz-fli.de> > wrote: > >> On 12/18/2015 09:05 PM, Robert Hanson wrote: >> > Oh, yes. .slice() copies all or part of an array. >> > >> The independence of 'n' was caused because the elements of the copied >> array were all undefined. I have changed the test and filled the array >> with values first: >> >> ---- Jmol script -------------------------- >> jsCommand = "n=1000000; a = new Array(n); for (var i = a.length;--i >= >> 0;) {a[i] = i;} t1=performance.now(); b = a.slice(0); >> t2=performance.now(); c = new Array(n); for (var i = a.length;--i >= 0;) >> { c[i] = a[i] } t3=performance.now(); dt1= t2 - t1; dt2= t3 - t2; a[5] = >> -5; msg='slice: ' + dt1 + 'ms copy: ' + dt2 + 'ms a[5]=' + a[5] + ' >> b[5]=' + b[5] + ' c[5]=' + c[5]; alert(msg)"; >> javascript @jsCommand; >> --------------------------------------------- >> >> Now 'slice' also depends on 'n': >> Firefox/HTML5: 4ms >> Firefox/Java: 4ms >> Chromium/HTML5: 10ms >> Chromium/Java: 7ms >> >> And the new values for 'copy' are: >> Firefox/HTML5: 500ms >> Firefox/Java: 4000ms >> Chromium/HTML5: 700ms >> Chromium/Java: 130ms >> >> Bob and others, do you have any idea why there is such a huge >> performance difference in running the same Javascript code from >> JSmol/Java or JSmol/HTML5 and that in a different direction for Firefox >> and Chrome? >> >> 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 >> > > > > -- > Robert M. Hanson > Larson-Anderson Professor of Chemistry > Chair, Department of Chemistry > St. Olaf College > Northfield, MN > http://www.stolaf.edu/people/hansonr > > > If nature does not answer first what we want, > it is better to take what answer we get. > > -- Josiah Willard Gibbs, Lecture XXX, Monday, February 5, 1900 > > -- Robert M. Hanson Larson-Anderson Professor of Chemistry Chair, Department of Chemistry St. Olaf College Northfield, MN http://www.stolaf.edu/people/hansonr If nature does not answer first what we want, it is better to take what answer we get. -- Josiah Willard Gibbs, Lecture XXX, Monday, February 5, 1900
------------------------------------------------------------------------------
_______________________________________________ Jmol-users mailing list Jmol-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jmol-users