Skip to content

Instantly share code, notes, and snippets.

@nise-nabe
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nise-nabe/8c5b8a75940d2739b67e to your computer and use it in GitHub Desktop.
Save nise-nabe/8c5b8a75940d2739b67e to your computer and use it in GitHub Desktop.
$ javac Main.java
$ time java Main
java Main  5.91s user 0.29s system 102% cpu 6.053 total
$ go build -o main
$ time ./main
./main  33.44s user 3.35s system 117% cpu 31.391 total
package main
import (
"runtime"
)
func init() {
runtime.GOMAXPROCS(runtime.NumCPU())
}
func main () {
for i := 0; i < 10000; i++ {
m := make(map[int]int)
for j := 0; j < 10000; j++ {
if _, exist := m[j]; !exist {
m[j] = i
}
}
}
}
import java.util.Map;
import java.util.HashMap;
class Main {
public static void main(String[] args){
for (int i = 0; i < 10000; i++) {
Map<Integer, Integer> m = new HashMap<Integer, Integer>();
for (int j = 0; j < 10000; j++) {
if (!m.containsKey(j)) {
m.put(j, i);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment