Last active
June 20, 2017 07:11
-
-
Save effective-light/1c9ae998753f647873a9b27da53219d4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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