commit
f054d5ab6e
|
@ -1,5 +1,5 @@
|
|||
# langs-performance
|
||||
C++ vs. Python vs. Perl vs. PHP vs. Java vs. NodeJS performance benchmark
|
||||
C++ vs. Python vs. Perl vs. PHP vs. Java vs. NodeJS vs. Go performance benchmark
|
||||
|
||||
Blog articles:
|
||||
* 2016: http://blog.famzah.net/2016/02/09/cpp-vs-python-vs-perl-vs-php-performance-benchmark-2016/
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
)
|
||||
|
||||
func getPrimes7(n int) []int {
|
||||
if n < 2 {
|
||||
return []int{}
|
||||
}
|
||||
if n == 2 {
|
||||
return []int{2}
|
||||
}
|
||||
|
||||
s := []int{}
|
||||
for i := 3; i <= n; i += 2 {
|
||||
s = append(s, i)
|
||||
}
|
||||
|
||||
var j int
|
||||
m := 3
|
||||
mroot := int(math.Sqrt(float64(n)))
|
||||
half := len(s)
|
||||
for i := 0; m <= mroot; {
|
||||
if s[i] != 0 {
|
||||
j = (m*m - 3) / 2
|
||||
s[j] = 0
|
||||
for j < half {
|
||||
s[j] = 0
|
||||
j += m
|
||||
}
|
||||
}
|
||||
i++
|
||||
m = 2*i + 3
|
||||
}
|
||||
|
||||
res := []int{}
|
||||
res = append(res, 2)
|
||||
for _, v := range s {
|
||||
if v != 0 {
|
||||
res = append(res, v)
|
||||
}
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
func main() {
|
||||
var res []int
|
||||
for i := 0; i < 10; i++ {
|
||||
res = getPrimes7(10000000)
|
||||
fmt.Printf("Found %d prime numbers.\n", len(res))
|
||||
}
|
||||
}
|
3
run.sh
3
run.sh
|
@ -33,6 +33,9 @@ C='g++' ; run_benchmark 'C++ (optimized with -O2)' "$C -Wall -O2 primes.cpp -o
|
|||
rm -f ./primes.cpp.out
|
||||
C='g++' ; run_benchmark 'C++ (not optimized)' "$C -Wall primes.cpp -o primes.cpp.out" './primes.cpp.out' "$C --version" 'head -n1'
|
||||
rm -f ./primes.cpp.out
|
||||
C='go' ; run_benchmark 'Go (not optimized, default compiler)' "$C build primes.go" './primes' "$C version" 'cat'
|
||||
go clean
|
||||
C='pypy' ; run_benchmark 'PyPy 2.7' 'true' "$C ./primes.py" "$C -V" 'cat'
|
||||
C='python2.7' ; run_benchmark 'Python 2.7' 'true' "$C ./primes.py" "$C -V" 'cat'
|
||||
C='python3.2' ; run_benchmark 'Python 3.2' 'true' "$C ./primes.py" "$C -V" 'cat'
|
||||
C='python3.5' ; run_benchmark 'Python 3.5' 'true' "$C ./primes.py" "$C -V" 'cat'
|
||||
|
|
Loading…
Reference in New Issue