1. Java sieve benchmark
- Posted by Robert Craig <robert_craig at COMPUSERVE.COM> Apr 18, 1997
- 1195 views
Paul Missman asked for a copy of the Euphoria and Java versions of the Sieve benchmark, used in making the claim that "Euphoria is 8x faster than Java". Here they are. On my Pentium-150 sieve.ex takes 4.1 seconds, while sieve.java takes 34 seconds, even after being "compiled" with javac -O (optimize). Euphoria is therefore about 8.3x faster. I'm using Euphoria 1.5 vs. Sun's Java interpreter 1.0.2. There are "just in time" compilers for Java that should provide faster execution (still slower than C), but I didn't benchmark against any of them. The iteration count is set to 10000, which is ok on my Pentium, but you might want to alter it for your machine. sieve.ex is less fancy than the one in demo\bench which adjusts the number of iterations according to the speed of the machine. Run the Euphoria program with: ex sieve -- takes 4 seconds to run Run the Java program with: javac -O sieve.java -- takes 5 seconds or so to compile java sieve -- takes 34 seconds to run ----- start of sieve.ex --------------------- --------------------------- -- Prime Sieve Benchmark -- --------------------------- constant SIZE = 500 -- finds primes up to SIZE*2+1 -- (only tests odd numbers) constant ON = 1, OFF = 0 constant SCREEN = 1 sequence flags procedure sieve() integer prime, start, count, still_prime for j = 1 to 10000 do count = 0 flags = repeat(ON, SIZE) for i = 1 to SIZE do still_prime = flags[i] if still_prime then prime = i + i prime = prime + 1 start = prime + i for k = start to SIZE by prime do flags[k] = OFF end for count = count + 1 end if end for end for printf(SCREEN, "count = %d\n", count) end procedure puts(SCREEN, "Prime Sieve benchmark ...\n") atom t t = time() sieve() printf(SCREEN, "time = %.2f\n", time()-t) ------------- end of sieve.ex ------------------ ------------- start of sieve.java -------------------- class sieve { public static void main(String args[]) { System.out.println("Prime Sieve benchmark ..."); int ON, OFF; int iter, flags[]; int SIZE, i, k, prime, start, count, still_prime; long t; t = System.currentTimeMillis(); SIZE = 500; // finds primes up to SIZE*2+1 ON = 1; OFF = 0; count = 0; // needed to avoid silly warning flags = new int[SIZE+1]; for (iter = 1; iter <= 10000; iter++) { count = 0; for (i = 1; i <= SIZE; i++) flags[i] = ON; for (i = 1; i <= SIZE; i++) { still_prime = flags[i]; if (still_prime == ON) { prime = i + i; prime = prime + 1; start = prime + i; for (k = start; k <= SIZE; k += prime) { flags[k] = OFF; } count++; } } } System.out.println("count = " + count); System.out.println("time = " + (System.currentTimeMillis() - t)/1000.0); } } ------------ end of sieve.java --------------------------- Regards, Rob Craig Rapid Deployment Software