Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   C Prime (http://www.programmingforums.org/showthread.php?t=1121)

lostcauz Nov 12th, 2004 6:35 PM

here's the slightly improved c code.
:

/*straight c code .00192 sec. number tested 111111113*/
/* .00449 sec alt test number tested 654159511*/
int is_prime2(int n){
  int i,k;
 
  if (n<=3)return 1;
  if(n&1==0)return 0;
  k=sqrt(n)+1;

  for (i=3;i<=k;i+=2){
  if(n%i==0)return 0;
  }
  return 1;
}


lostcauz Nov 12th, 2004 10:37 PM

Now the pointer contains roughly the square root of the number we are testing for prime. We will now *blaze* to the result. :rock:

kurifu Nov 12th, 2004 11:07 PM

So curiously, what C/C++ code did you compare this execution too? I suspect that one would be able to match the speed of execution without having to break down into an inline assembly at all.

lostcauz Nov 12th, 2004 11:24 PM

The C code was listed in the first post as was this statement.
Quote:

Obviously the C code could have been further optimized before the comparison.
I was simply recanting an experience for those that might be interested. Even the assembly code here is still not the best and I've seen a better algorithm already. This was just for my fun. You are welcome to optimize either or both of them if you wish. ;)


All times are GMT -5. The time now is 1:05 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC