-
-
Save apg/95163a8f6c2925f046089557223e725c to your computer and use it in GitHub Desktop.
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
import json | |
import random | |
import string | |
def rstr(N): | |
return ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(N)) | |
data = {} | |
for i in range(100000): | |
x = {} | |
for j in range(10): | |
x[rstr(10)] = rstr(100) | |
data[str(i)] = x | |
with open('huge.json', 'w') as y: | |
json.dump(data, y) | |
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 ( | |
"encoding/json" | |
"fmt" | |
"os" | |
"time" | |
) | |
func main() { | |
input, err := os.Open("huge.json") | |
if err != nil { | |
fmt.Printf("File error: %v\n", err) | |
os.Exit(1) | |
} | |
var i interface{} | |
before := time.Now() | |
dec := json.NewDecoder(input) | |
err = dec.Decode(&i) | |
if err != nil { | |
fmt.Printf("Encode error: %v\n", err) | |
os.Exit(1) | |
} | |
fmt.Println("LOAD: ", time.Since(before)) | |
output, err := os.Create("out.go.json") | |
if err != nil { | |
fmt.Printf("File error (write): %v\n", err) | |
os.Exit(1) | |
} | |
before = time.Now() | |
enc := json.NewEncoder(output) | |
err = enc.Encode(i) | |
if err != nil { | |
fmt.Printf("Encode error: %v\n", err) | |
os.Exit(1) | |
} | |
fmt.Println("DUMP: ", time.Since(before)) | |
} |
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
bench$ for n in `seq 1 3`; do make go python > /dev/null; done | |
bench$ make go python | |
go build ./go.go | |
echo "Running go version." | |
Running go version. | |
./go | |
LOAD: 2.016554434s | |
DUMP: 1.478200338s | |
echo "Running python version" | |
Running python version | |
python py.py | |
LOAD elapsed=1.56545710564 | |
DUMP elapsed=3.07746505737 | |
bench$ go version | |
go version go1.9 darwin/amd64 | |
agwozd-ltm2:bench agwozdziewycz$ python --version | |
Python 2.7.10 | |
bench$ du -h * | |
114M huge.json | |
112M out.go.json | |
114M out.py.json |
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
go: | |
go build ./go.go | |
echo "Running go version." | |
./go | |
python: | |
echo "Running python version" | |
python py.py | |
.PHONY: go python |
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
import json | |
import time | |
before = time.time() | |
with open('huge.json') as x: | |
obj = json.load(x) | |
print("LOAD elapsed={}".format(time.time() - before)) | |
before = time.time() | |
with open('out.py.json', 'w') as y: | |
json.dump(obj, y) | |
print("DUMP elapsed={}".format(time.time() - before)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment