Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bench test your PC!
#2
Code:
if (i == num)
                {
                    Console.WriteLine(num);
                }

That makes me cry. Writelines are very CPU intensive. Only the end result is needed. Sad

Code:
Stopwatch timer = new Stopwatch();
            timer.Start();
            int num;
            int i;
            for (num = 3; num <= cap; num += 2)
            {
                for (i = 2; i < num; i++)
                {
                    if (num % i == 0)
                    {    
                        break;
                    }
                }
            }

There are other optimizations you could use, but these are some pretty good ones for the moment. I guess it's also because I was trained in the ANSI standard. >_>
Reply


Messages In This Thread
Bench test your PC! - by AngelSL - 2008-08-30, 03:50 AM
Bench test your PC! - by Fiel - 2008-08-30, 04:12 AM
Bench test your PC! - by BladeHavoc - 2008-08-30, 04:24 AM
Bench test your PC! - by AngelSL - 2008-08-30, 04:41 AM
Bench test your PC! - by BladeHavoc - 2008-08-30, 04:51 AM
Bench test your PC! - by AngelSL - 2008-08-30, 05:22 AM
Bench test your PC! - by Kabanaw - 2008-08-30, 07:50 AM
Bench test your PC! - by Hazzy - 2008-08-30, 09:20 AM
Bench test your PC! - by Fiel - 2008-08-30, 10:15 AM
Bench test your PC! - by Manda - 2008-09-01, 01:11 PM
Bench test your PC! - by Russt - 2008-09-01, 02:46 PM
Bench test your PC! - by Beloved - 2008-09-03, 04:49 AM
Bench test your PC! - by wobbufet - 2008-09-03, 11:44 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)