473,394 Members | 1,935 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Standard Sieve performance

/*

SIEVE OF ERATOSTHENES from BYTE magazine --------------------

-- compiled with jdk 1.1.7b with optimize on ( -O)
-- Run times on 300 MHz Pentium 2 Windows 95
-- in order of output, from fresh boot

-------------------------------------------------------------

JDK 1.1.7B

Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_03-b02)
Java HotSpot(TM) Client VM (build 1.4.1_03-b02, mixed mode)

Microsoft Jview 5.00.3805

-------------------------------------------------------------

C:\Java\Sieve>makerun Sieve 10000
adding: Sieve.class (in=1033) (out=630) (deflated 39%)
10000 iterations
1899 primes
5720 milliseconds
10000 iterations
1899 primes
15430 milliseconds
10000 iterations
1899 primes
6100 milliseconds
C:\Java\Sieve>makerun Sieve 10000
adding: Sieve.class (in=1033) (out=630) (deflated 39%)
10000 iterations
1899 primes
5330 milliseconds
10000 iterations
1899 primes
14450 milliseconds
10000 iterations
1899 primes
6100 milliseconds

-------------------------------------------------------------

C:\Java\Sieve>set classpath=

C:\Java\Sieve>gcj --version
GCJ.EXE (GCC) 3.3.1 (mingw special 20030804-1)
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

C:\Java\Sieve>gcj -O3 --main=Sieve Sieve.java

C:\Java\Sieve>a 10000
10000 iterations
1899 primes
7360 milliseconds

C:\Java\Sieve>a 10000
10000 iterations
1899 primes
7580 milliseconds

-------------------------------------------------------------

maw

*/

public class Sieve {
static final int TSIZE = 8192;
public static void main(String args[]) {
int NUM = Integer.parseInt(args[0]);
byte [] flags = new byte[TSIZE + 1];
int count = 0;
System.out.print(NUM + " iterations \n");
long t1 = System.currentTimeMillis();
while (NUM-- > 0) {
count = 0;
for (int i=0; i <= TSIZE; i++) {
flags[i] = 1;
}
for (int i=0; i <= TSIZE; i++) {
if (flags[i] == 1) {
int prime = i + i + 3;
int k = i + prime;
while( k <= TSIZE) {
flags[k] = 0;
k = k + prime;
}
count++;
}
}
}
long t2 = System.currentTimeMillis();
System.out.print(count + " primes \n");
System.out.print((t2 - t1) + " milliseconds \n");
}
}
Jul 17 '05 #1
0 2258

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: MSiegel | last post by:
hi there! i have to program the sieve of eratosthenes in php as a homework. after i had created an html file where the maximum is set i wrote a php script which doesn't work properly - actually...
43
by: Steven T. Hatton | last post by:
Now that I have a better grasp of the scope and capabilities of the C++ Standard Library, I understand that products such as Qt actually provide much of the same functionality through their own...
104
by: fieldfallow | last post by:
Hello all, Is there a function in the standard C library which returns a prime number which is also pseudo-random? Assuming there isn't, as it appears from the docs that I have, is there a...
15
by: Steve Bergman | last post by:
Just wanted to report a delightful little surprise while experimenting with psyco. The program below performs astonoshingly well with psyco. It finds all the prime numbers < 10,000,000 ...
23
by: Nishant Saini | last post by:
Dear All, We have a database which contains many tables which have millions of records. When We attach the database with MS SQL Server 2005 Standard Edition Server and run some queries (having...
4
by: knuxus | last post by:
Hey everyone.... I would appreciate any type of help if anyone could explain me how to translate this algorithm to Visual Basic, im still learning and i would appreciate this algorithm to my prime...
2
Blackout
by: Blackout | last post by:
Hi, I'm having problems with this C program. Whenever I run it, it doesn't print anything. The program is supposed to compute and display all the prime numbers from 1 - 300 using the sieve of...
5
by: jzakiya | last post by:
This is to announce the release of my paper "Ultimate Prime Sieve -- Sieve of Zakiiya (SoZ)" in which I show and explain the development of a class of Number Theory Sieves to generate prime...
4
by: jzakiya | last post by:
Update: 2008/11/03 Architecture & coding improvements. Renamed generators. I am 90% finished writing up a mathematical analysis of my method. In the process I found an architectural...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.