Skip to content

Instantly share code, notes, and snippets.

@kmizu
Created November 29, 2017 05:25
Show Gist options
  • Save kmizu/374f654d3ee581fca36f018e0262733d to your computer and use it in GitHub Desktop.
Save kmizu/374f654d3ee581fca36f018e0262733d to your computer and use it in GitHub Desktop.
Python VS. Scala
import time
def main():
start = time.time()
z = 0
for i in range(0, 100000000):
z += 1
print(z)
end = time.time()
print(end - start)
for x in range(0, 10):
main()
def main = {
val start = System.currentTimeMillis()
var z = 0
for(i <- 0 until 100000000) {
z += 1
}
println(z)
val end = System.currentTimeMillis()
println(end - start)
}
for(_ <- 1 to 10) {
main
}
$ python3 bench.py
100000000
12.788141965866089
100000000
12.269313097000122
100000000
11.560492038726807
100000000
10.881245136260986
100000000
11.233325004577637
100000000
12.205527067184448
100000000
10.37359094619751
100000000
10.950555324554443
100000000
12.733907222747803
100000000
11.066769123077393
[kota_mizushima]$ scala bench.scala
100000000
106
100000000
95
100000000
88
100000000
92
100000000
97
100000000
75
100000000
87
100000000
93
100000000
91
100000000
101
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment