Speed of applets vs. compiled scripts
Speed of applets vs. compiled scripts
- Subject: Speed of applets vs. compiled scripts
- From: email@hidden
- Date: Mon, 28 Jan 2002 12:09:36 -0500
On Mon, 28 Jan 2002 11:18:36 -0500, "Marc K. Myers" <email@hidden> asked,
>
I wrote a little script to generate a list of all the prime numbers from
>
2 to 10001. I ran it under Script Editor and it took 586 seconds. Just
>
out of curiosity I ran the same script as an applet. It ran for 998
>
seconds! Can anyone tell me why there is such a difference?
Just guessing, but in a cooperative multitasking environment, the applet shell
seems to be more cooperative than Script Editor.
>
I had
>
expected the applet to run faster since it didn't have the overhead of
>
the Script Editor application. Also, is there a faster algorithm for
>
generating a list of primes?
You only have to try divisors up to sqrt(i), rather than i/2. As i gets large,
the savings are significant. (Specifically, you get an advantage of sqrt(i)/2.)
--
Scott Norton Phone: +1-703-299-1656
DTI Associates, Inc. Fax: +1-703-706-0476
2920 South Glebe Road Internet: email@hidden
Arlington, VA 22206-2768 or email@hidden