On Thu, 2 Jun 2016 03:19:32 +0200 Victor Stinner victor.stinner@gmail.com wrote:
I'm interested by the very basic perf.py internal text format: one timing per line, that's all. But it's incomplete, the "loops" informaiton is not stored. Maybe a binary format is better? I don't know yet.
Just use a simple JSON format.
Regards
Antoine.
2016-06-02 9:17 GMT+02:00 Antoine Pitrou solipsis@pitrou.net:
Just use a simple JSON format.
Yeah, Python 2.7 includes are JSON parser and JSON is human readble (but not really designed to be modified by a human).
I had a technical issue: I wanted to produce JSON output *and* keep nice human output at the same time. I found a nice trick: by default write human output to stdout, but write JSON to stdout and human output to stderr in JSON mode.
$ python3 -m perf.timeit --json 1+1 > run.json ......................... Average: 18.3 ns +- 0.3 ns (25 runs x 3 samples x 10^7 loops)
$ python3 -m perf < run.json Average: 18.3 ns +- 0.3 ns (25 runs x 3 samples x 10^7 loops)
$ python3 -m perf.timeit --metadata --json 1+1 > run.json Metadata:
......................... Average: 18.2 ns +- 0.0 ns (25 runs x 3 samples x 10^7 loops)
$ python3 -m perf < run.json Metadata:
There are two kinds of objects: a single run, or a result composed of multiple runs. The format is one JSON object per line.
$ python3 -m perf.timeit --raw --json 1+1 > run1.json warmup 1: 18.3 ns sample 1: 18.3 ns sample 2: 18.3 ns sample 3: 18.3 ns
$ python3 -m perf.timeit --raw --json 1+1 > run2.json warmup 1: 18.2 ns sample 1: 18.2 ns sample 2: 18.2 ns sample 3: 18.2 ns
$ python3 -m perf.timeit --raw --json 1+1 > run3.json warmup 1: 18.2 ns sample 1: 18.2 ns sample 2: 18.2 ns sample 3: 18.2 ns
$ python3 -m perf < run1.json # single run Average: 18.3 ns +- 0.0 ns (3 samples x 10^7 loops)
$ cat run1.json run2.json run3.json | python3 -m perf # 3 runs Average: 18.2 ns +- 0.0 ns (3 runs x 3 samples x 10^7 loops)
Victor