Subj : Re: Performance: Another test of Java vs JavaScript ... To : netscape.public.mozilla.jseng From : "Sterling Bates" Date : Fri Oct 17 2003 12:30 am "Neil Kolban" wrote in message news:bmno89$7pl2@ripley.netscape.com... > Folks, > > Here are a couple of code fragments.... the first is Java and the 2nd is JavaScript running under Rhino. > > > > > public class Perf2 { > public static void main(String[] args) { > String string = "ABCDEFGHIJ"; > String sub; > int i = 1; > long start = System.currentTimeMillis(); > while (i<200000) > { > sub = string.substring(3,6); > i = i + 1; > } > long diff = System.currentTimeMillis() - start; > System.out.println("Elapsed: " + diff); > } > } It looks like you're using constant values in your loop, which the compiler can optimize out for the most part. I would try adding some randomness to the Java code and recheck the results. It may not affect the timing by much, but would rule out at least some compiler optimizations. This is also a good showing of what Javascript is good for, and what it is not. It's not intended for massive loops, nor as a compiled-language replacement. It's a quick way to write and customize software, and performs with more than adequate speed when used judiciously. Sterling .