Re: [Jmol-developers] Loop speed optimization potential
On Wed, Apr 8, 2015 at 4:48 AM, Rolf Huehne rhue...@fli-leibniz.de wrote: Q: Does 'i' contain the hash key (as in Perl) or the value? the key -- BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT Develop your own process in accordance with the BPMN 2 standard Learn Process modeling best practices with Bonita BPM through live exercises http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_ source=Sourceforge_BPM_Camp_5_6_15utm_medium=emailutm_campaign=VA_SF___ Jmol-developers mailing list Jmol-developers@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jmol-developers
Re: [Jmol-developers] Loop speed optimization potential
Rolf, I think you could have a lot of fun with the JavaScript functions Jmol provides. Jmol never does loops like that. Instead it initializes a three-dimensional binary tree -- we call it a binary forest :) -- and you specify a point and a radius, then iterate until done. It is far far faster. The class is java.bspt.Bspf. It could be used outside of Jmol, I think. I did some minor tweaks of the FOR command, and I also added what I think is a nice syntax that loops 2-3 times faster than (i=1; i n; i++) for (var i FROM [1 1] ) { ...increments up } for (var i FROM [10 -1]) { ...increments down } http://chemapps.stolaf.edu/jmol/zip/jmol-14.3.13_2015.04.05.zip Jmol.___JmolVersion=14.3.13_2015.04.05 code: rewriting FOR loop code to enhance performance new feature: set showScript -1 -- turns off history (on when commands come from the keyboard) -- stops every-second JavaScript interruptions -- Caution! new feature: for (var i FROM [a, b]) {...} -- same as for (var i = a; i = b; i++) when a b -- same as for (var i = a; i = b; i--) when a b -- much more efficient bug fix: for (var i in hashArray) {} broken (also in 14.2; not fixed there) -- Dive into the World of Parallel Programming The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/___ Jmol-developers mailing list Jmol-developers@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jmol-developers
Re: [Jmol-developers] Loop speed optimization potential
Hi Rolf I was about to suggest what Bob is putting forward: if Javascript is faster, you might take part of the code out from JmolScript into JavaScript. I believe he has demo'ed how. Another idea: I found that in Javascript there is much improvement in loops when they are decrementing instead of incrementing the control variable. Namely, changing for (i=0; in; i++) { ... } to i=n; while (i--) { ... } Maybe you can squeeze some juice also in JmolScript. I did not understand the real reason for that, but it does work. There is abundant documentation in the web. -- Dive into the World of Parallel Programming The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ ___ Jmol-developers mailing list Jmol-developers@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jmol-developers
Re: [Jmol-developers] Loop speed optimization potential
Rolf, you are definitely pushing the limit there, I think. What exactly happens inside the loop you are really interested in using? If it is anything much, then the looping itself is going to be insignificant compared to the other processing. I probably will regret suggesting this, but something to consider might be a hybrid, where you retrieve key Jmol variables into JavaScript, run whatever in Javascript, then put them back (if desired). The example below is for an integer: script var _vi = jmolApplet0._applet.viewer.g.htUserVariables.get(i) var i = _vi.intValue // Object { index: 2147483647, flags: 3, myName: i, tok: 2, intValue: 0 } // then do anything with that you want, and finally _vi.intValue = /script Other Jmol types will work -- after all, it's *all *JavaScript. (This could not be done with the Java applet, of course.) Jmol variable types include public final static int integer= 2; public final static int decimal= 3; public final static int string = 4; public final static int hash = 6; // associative array; Hashtable public final static int varray = 7; // ListScriptVariable public final static int point3f= 8; public final static int point4f= 9; public final static int bitset = 10; public final static int matrix3f = 11; public final static int matrix4f = 12; public final static int listf = 13; // listf list-float is specifically for xxx.all.bin, public final static int context= 14; public final static int barray = 15; // byte array Believe it or not, you can change variables from one type to another this way, though I would not necessarily recommend doing that. var _vi = jmolApplet0._applet.viewer.g.htUserVariables.get(i); var i = _vi.intValue; _vi.tok = 2; // now Jmol's i variable is a float! _vi.value = new Float(i); The Jmol JAVASCRIPT command could be used to mix and match Jmol scripting with JavaScript. Mind you, _applet.viewer.g.htUserVariables is NOT a public entity -- I reserve the right to change its name at any time! Bob -- Dive into the World of Parallel Programming The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/___ Jmol-developers mailing list Jmol-developers@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jmol-developers