commit
29cc736cd6
|
@ -1,5 +1,5 @@
|
||||||
# langs-performance
|
# langs-performance
|
||||||
C++ vs. Python vs. Perl vs. PHP vs. Java vs. NodeJS vs. Go vs. Ruby performance benchmark
|
C++ vs. Python vs. Perl vs. PHP vs. Java vs. NodeJS vs. Go vs. Ruby vs. Rust vs. Swift performance benchmark
|
||||||
|
|
||||||
Blog articles:
|
Blog articles:
|
||||||
* 2016: https://blog.famzah.net/2016/09/10/cpp-vs-python-vs-php-vs-java-vs-others-performance-benchmark-2016-q3/
|
* 2016: https://blog.famzah.net/2016/09/10/cpp-vs-python-vs-php-vs-java-vs-others-performance-benchmark-2016-q3/
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
func get_primes7(_ n: Int) -> [Int] {
|
||||||
|
if n < 2 {
|
||||||
|
return []
|
||||||
|
} else if n == 2 {
|
||||||
|
return [2]
|
||||||
|
}
|
||||||
|
|
||||||
|
// do only odd numbers starting at 3
|
||||||
|
var s = Array(stride(from: 3, to: n, by: 2))
|
||||||
|
|
||||||
|
let mroot: Int = Int(sqrt(Double(n)))
|
||||||
|
let half = s.count
|
||||||
|
var i = 0
|
||||||
|
var m = 3
|
||||||
|
while m <= mroot {
|
||||||
|
if s[i] != 0 {
|
||||||
|
var j: Int = (m*m - 3) / 2
|
||||||
|
while j < half {
|
||||||
|
s[j] = 0
|
||||||
|
j += m
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i += 1
|
||||||
|
m += 2
|
||||||
|
}
|
||||||
|
return [2] + s.filter { $0 != 0 }
|
||||||
|
}
|
||||||
|
|
||||||
|
if let period_time_var = ProcessInfo.processInfo.environment["RUN_TIME"] {
|
||||||
|
let start_time = Date()
|
||||||
|
let period_time = Int(period_time_var)!
|
||||||
|
|
||||||
|
while Int(Date().timeIntervalSince(start_time)) < period_time {
|
||||||
|
let res = get_primes7(10_000_000)
|
||||||
|
print("Found \(res.count) prime numbers.")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
print("RUN_TIME not found.")
|
||||||
|
}
|
||||||
|
|
11
run.sh
11
run.sh
|
@ -110,10 +110,21 @@ go clean
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
||||||
|
C='swiftc' ; SRC='primes.swift' ; run_benchmark 'Swift (optimized with -O)' \
|
||||||
|
"$C $SRC -o primes.swift.out -O -swift-version 4" './primes.swift.out' "$C -version" 'head -n1' "$SRC"
|
||||||
|
rm -f ./primes.swift.out
|
||||||
|
|
||||||
|
C='swiftc' ; SRC='primes.swift' ; run_benchmark 'Swift (not optimized)' \
|
||||||
|
"$C $SRC -o primes.swift.out -swift-version 4" './primes.swift.out' "$C -version" 'head -n1' "$SRC"
|
||||||
|
rm -f ./primes.swift.out
|
||||||
|
|
||||||
|
##
|
||||||
|
|
||||||
C='pypy' ; SRC='primes.py' ; run_benchmark 'Python 2.7 + PyPy' 'true' "$C $SRC" "$C -V" 'cat' "$SRC"
|
C='pypy' ; SRC='primes.py' ; run_benchmark 'Python 2.7 + PyPy' 'true' "$C $SRC" "$C -V" 'cat' "$SRC"
|
||||||
C='python2.7' ; SRC='primes.py' ; run_benchmark 'Python 2.7' 'true' "$C $SRC" "$C -V" 'cat' "$SRC"
|
C='python2.7' ; SRC='primes.py' ; run_benchmark 'Python 2.7' 'true' "$C $SRC" "$C -V" 'cat' "$SRC"
|
||||||
C='python3.2' ; SRC='primes.py' ; run_benchmark 'Python 3.2' 'true' "$C $SRC" "$C -V" 'cat' "$SRC"
|
C='python3.2' ; SRC='primes.py' ; run_benchmark 'Python 3.2' 'true' "$C $SRC" "$C -V" 'cat' "$SRC"
|
||||||
C='python3.5' ; SRC='primes.py' ; run_benchmark 'Python 3.5' 'true' "$C $SRC" "$C -V" 'cat' "$SRC"
|
C='python3.5' ; SRC='primes.py' ; run_benchmark 'Python 3.5' 'true' "$C $SRC" "$C -V" 'cat' "$SRC"
|
||||||
|
C='python3.6' ; SRC='primes.py' ; run_benchmark 'Python 3.6' 'true' "$C $SRC" "$C -V" 'cat' "$SRC"
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue