-
-
Save masnun/e0201b10f70fd719edb9b95863b3a3db to your computer and use it in GitHub Desktop.
Cython vs Golang
This file contains 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 do(): | |
cdef long sum = 0 | |
cdef int i = 0 | |
for i in range(2000): | |
sum += i*i | |
print(sum) |
This file contains 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
package main | |
import "fmt" | |
func main() { | |
sum := 0 | |
for i := 0; i < 2000; i++ { | |
sum += i * i | |
} | |
fmt.Println(sum) | |
} |
This file contains 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
# The first run would need to compile `cy.pyx` module, so benchmark from the 2nd run | |
# In real life, we would use setup.py to compile the module into a shared lib before hand | |
# and we would not need the pyximport stuff. But for quick benchmark, pyximport is more convenient. | |
import pyximport | |
pyximport.install() | |
import cy | |
cy.do() |
This file contains 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
➜ playground time go run main.go | |
2664667000 | |
go run main.go 0.43s user 0.08s system 119% cpu 0.426 total | |
➜ playground time python main.py | |
2664667000 | |
python main.py 0.20s user 0.08s system 97% cpu 0.286 total | |
➜ playground |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment