a program that writes the primes

This is a discussion on a program that writes the primes within the C++ Programming forums, part of the General Programming Boards category; hey, last night i made a program that will tell you whether or not a program is prime (with a ...

  1. #1
    Geo Geo Geo-Fry
    Join Date
    Feb 2003
    Posts
    116

    a program that writes the primes

    hey, last night i made a program that will tell you whether or not a program is prime (with a lot of help from some other people, most notably RoD and Alpha) and i used it to create a basic program that lists out the amount of primes you specify, and, if its more that 300 (the amount of lines in the DOS window) it prints them to primes.txt. i was wondering how long it takes you guys for the program to print out a lot of them. for my 2.0 gig processer with i think 512 ram its instant up to about 10000 (ten thousand), and took close to 5 minutes for the first 200000(two hundred thousand). if you could download it and try it and give me some times, it would be appreciated. the program will tell you when the primes are written out.
    Attached Files Attached Files
    "You can lead a man to Congress, but you can't make him think."
    "The Grand Old Duke of York
    -He had ten thousand men.
    -His case comes up next week."
    "Roses are red, violets are blue, I'm schizophrenic, and so am I."
    "A computer once beat me at chess, but it was no match for me at kick boxing."
    "More and more of our imports are coming from overseas."
    --George W. Bush
    "If it weren't for electricity, we'd all be wacthing TV by candlelight."
    --George W. Bush

  2. #2
    Registered User
    Join Date
    Feb 2003
    Posts
    162
    Try posting source code...not many people (if any) will run executables.....i ran it, and 200,000 primes was a little under 3 minutes.....(phone rang, and when i came back, it was done, and it had hit the 3 minute mark)....XP 1700+ and 768 PC 2100

  3. #3
    Geo Geo Geo-Fry
    Join Date
    Feb 2003
    Posts
    116
    ok i will and thx for the input
    Attached Files Attached Files
    "You can lead a man to Congress, but you can't make him think."
    "The Grand Old Duke of York
    -He had ten thousand men.
    -His case comes up next week."
    "Roses are red, violets are blue, I'm schizophrenic, and so am I."
    "A computer once beat me at chess, but it was no match for me at kick boxing."
    "More and more of our imports are coming from overseas."
    --George W. Bush
    "If it weren't for electricity, we'd all be wacthing TV by candlelight."
    --George W. Bush

  4. #4
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    I ran it on my PII 350 with 128 SD RAM with Windows 2000 pro, and it took close to 29 minutes to get to the 200,000 mark!!

    Looks like it might be time to upgrade lol

    ~ Paul

  5. #5
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    P3 1GHz, 512MB of RAM, 12min. I've put together a more efficient version, which only checks divisibility by prime numbers less than the square root, rather than all numbers less than the square root. On my PC, it spits out 200k primes in 19 seconds. I've attached the source if you wanna look at it.
    Attached Files Attached Files
    Last edited by XSquared; 03-28-2003 at 11:04 PM.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  6. #6
    Registered User
    Join Date
    Feb 2003
    Posts
    162
    mmm 12 seconds on XSquared's code

  7. #7
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    26 seconds with X squared's code on my "beast" (PII 350).

    I guess this is a really good way of testing how efficient your code is.

    Edit: It would be fun to have a competition like this to see who could create the fastest/most efficient prime number generator, just everyones computer is different. Oh well.

    ~ Paul
    Last edited by nickname_changed; 03-28-2003 at 10:31 PM.

  8. #8
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278
    Geo-Fry:

    I didn't really look at your code, but I think it is writing the primes to disk as it computes them. If you want a real time for speed, you should only time the portion that computes the primes in memory, before taking disk writes into account. Also, I thought the program was going to do the timing for me, so I didn't time it accurately. It took approx. 3 minutes on my 1700+ XP athlon.

    XSquared:

    Those are definite improvements any prime-computing program should have. Your program took 13 seconds on my system.

  9. #9
    Geo Geo Geo-Fry
    Join Date
    Feb 2003
    Posts
    116
    jeeze, i guess xsquared is just too smart for me...
    i looked at your code and i was like "WHOA! WTF IS THAT?" cause it was all wierd, so small and compact yet speedy and fast, your my hero
    "You can lead a man to Congress, but you can't make him think."
    "The Grand Old Duke of York
    -He had ten thousand men.
    -His case comes up next week."
    "Roses are red, violets are blue, I'm schizophrenic, and so am I."
    "A computer once beat me at chess, but it was no match for me at kick boxing."
    "More and more of our imports are coming from overseas."
    --George W. Bush
    "If it weren't for electricity, we'd all be wacthing TV by candlelight."
    --George W. Bush

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 01:27 PM
  2. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  3. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 11:58 PM
  4. I need some help with my program please.
    By agentxx04 in forum C Programming
    Replies: 9
    Last Post: 09-26-2004, 08:51 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 11:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21