Skip to content

Instantly share code, notes, and snippets.

@effective-light
Last active June 20, 2017 07:11
Show Gist options
  • Select an option

  • Save effective-light/1c9ae998753f647873a9b27da53219d4 to your computer and use it in GitHub Desktop.

Select an option

Save effective-light/1c9ae998753f647873a9b27da53219d4 to your computer and use it in GitHub Desktop.
$ time python prime.py 1000
...
python prime.py 0.05s user 0.01s system 95% cpu 0.059 total
$ time ./a.out 1000
...
./a.out 0.00s user 0.00s system 56% cpu 0.006 total
$ time java Prime 1000
...
java Prime 0.09s user 0.02s system 130% cpu 0.082 total
#include <stdbool.h>
bool is_prime(int n)
{
if ( n <= 1 )
return false;
for ( int i = 2; i < n; i++ )
{
if ( n % i == 0 )
return false;
}
return true;
}
public class Prime
{
public boolean isPrime(int n)
{
if ( n <= 1 )
return false;
for ( int i = 2; i < n; i++ )
{
if ( n % i == 0 )
return false;
}
return true;
}
}
def is_prime(n: int) -> bool:
if n <= 1:
return False
for i in range(2, n):
if n % i == 0:
return False
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment