Go vs Java WordSorter comparison. Faster and less LOC in Golang. (github.com) 3 points by jemeshsu 13y ago ↗ HN
[–] st3fan 13y ago ↗ The Go version does not compile. It fails with:main.go:11:5: import "wordsort": cannot find package
[–] st3fan 13y ago ↗ The problem with these two examples is that they are not doing the same thing.The Go version limits the number of concurrent Go routines to the number of processors.The Java version on the other hand spawns 128 threads that all get started simultaneously.When I remove the concurrency limiting code from the Go version it runs on 1575ms instead of 750ms. (On an 1.8 GHz i7 MacBook Air)The line in question is:runtime.GOMAXPROCS(runtime.NumCPU())Imagine what would happen if the Java code used a ExecutorService to limit the number of concurrent threads in a similar way.
3 comments
[ 2.8 ms ] story [ 18.4 ms ] threadmain.go:11:5: import "wordsort": cannot find package
The Go version limits the number of concurrent Go routines to the number of processors.
The Java version on the other hand spawns 128 threads that all get started simultaneously.
When I remove the concurrency limiting code from the Go version it runs on 1575ms instead of 750ms. (On an 1.8 GHz i7 MacBook Air)
The line in question is:
runtime.GOMAXPROCS(runtime.NumCPU())
Imagine what would happen if the Java code used a ExecutorService to limit the number of concurrent threads in a similar way.