Skip to content

Instantly share code, notes, and snippets.

@tdoly
Last active March 2, 2018 13:14
Show Gist options
  • Save tdoly/63c1c4743b11126b848c22b208767254 to your computer and use it in GitHub Desktop.
Save tdoly/63c1c4743b11126b848c22b208767254 to your computer and use it in GitHub Desktop.
python/go/swift vs
package main
import "fmt"
var sum = 0
func main() {
for e := 0; e < 30; e++ {
sum = 0
var x[]int
for i := 0; i < 1000000; i++ {
x = append(x, i)
}
var y[]int
for i := 0; i < 1000000-1; i++ {
y = append(y, x[i] + x[i+1])
}
for i := 0; i < 1000000; i+=100 {
sum += y[i]
}
}
fmt.Println(sum)
}
#!/usr/bin python
sum = 0
for e in xrange(30):
sum = 0
x = []
for i in xrange(1000000):
x.append(i)
y = []
for i in xrange(1000000 - 1):
y.append(x[i] + x[i+1])
i = 0
for i in xrange(0, 1000000, 100):
sum += y[i]
print sum
#!/usr/bin/xcrun swift
var sum = 0
for e in 0..<30 {
sum = 0
var x: Array<Int> = []
for (var i=0; i<1000_000; i++) {
x.append(i)
}
var y: Array<Int> = []
for (var i=0; i<1000_000-1; i++) {
y.append(x[i] + x[i+1])
}
for (var i=0; i<1000_000; i+=100){
sum += y[i]
}
}
print(sum)
@tdoly
Copy link
Author

tdoly commented Dec 4, 2016

➜ 63c1c4743b11126b848c22b208767254 git:(master) time go run test_go.go
9999010000
go run test_go.go 0.88s user 0.09s system 91% cpu 1.068 total

➜ 63c1c4743b11126b848c22b208767254 git:(master) time ./test_swift.swift
9999010000
./test_swift.swift 1.85s user 0.59s system 97% cpu 2.508 total

➜ 63c1c4743b11126b848c22b208767254 git:(master) time python test_python.py
9999010000
python test_python.py 11.73s user 0.64s system 92% cpu 13.312 total

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment