[geeks] javascript tutorial sought?

Jonathan C. Patschke jp at celestrion.net
Tue Aug 12 21:39:56 CDT 2008


On Tue, 12 Aug 2008, Sridhar Ayengar wrote:

> Measure it.  Java's has more overhead.

javascript:
   var i, j;
   var loopCount;

   for (loopCount = 0 ; loopCount < 100 ; ++loopCount) {
     j = 1;
     for (i = 1 ; i < 100000000; ++i) { j = j * Math.sin(i); }
   }

$ time js jtest.js

   real    308m17.517s
   user    303m35.187s
   sys     3m47.281s


java:
   public class jtest {
     public static void main(String args[]) {
       double  i, j;
       double  loopCount;

       for (loopCount = 0.0 ; loopCount < 100.0 ; loopCount += 1.0) {
         j = 1.0;
         for (i = 1.0 ; i < 100000000.0; i += 1.0) {
           j = j * Math.sin(i);
         }
       }
     }
   }

$ javac jtest.java
$ time java jtest

   real    127m24.323s
   user    126m54.301s
   sys     0m7.618s


The java process kept its reserved memory fixed at 18MB.  The js process
repeatedly ate about 80MB before GCing and dropping back to 4MB.  This is
on FreeBSD 7.0p1/amd64 with SpiderMonkey 1.5 and Java "diablo" 1.5.0.  The
test system has 8 Xeon cores and 8GB memory, so the benchmark shouldn't be
adversely affected by the fact that the system wasn't completely quiesced
beforehand.  The tests were not run concurrently.

Another thing to consider is that the bare Spidermonkey interpreter has no
DOM overhead, no XUL overhead, isn't part of a GUI event loop, etc.  It'll
only get more sluggish in the larger context of a bloated application like
Firefox.

-- 
Jonathan Patschke | "There is more to life than increasing its speed."
Elgin, TX         |                                   --Mahatma Gandhi
USA               |



More information about the geeks mailing list