mirror of
https://github.com/sharkdp/hyperfine.git
synced 2024-11-25 08:33:59 +03:00
Nicer whiskers plot
- add missing encoding when opening input file - add labels to x ticks, rotated by 45 deg - sort data by median, ascending
This commit is contained in:
parent
5493cf5039
commit
5c9d7a8b1e
@ -24,7 +24,7 @@ parser.add_argument(
|
|||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
with open(args.file) as f:
|
with open(args.file, encoding='utf-8') as f:
|
||||||
results = json.load(f)["results"]
|
results = json.load(f)["results"]
|
||||||
|
|
||||||
if args.labels:
|
if args.labels:
|
||||||
@ -32,6 +32,11 @@ if args.labels:
|
|||||||
else:
|
else:
|
||||||
labels = [b["command"] for b in results]
|
labels = [b["command"] for b in results]
|
||||||
times = [b["times"] for b in results]
|
times = [b["times"] for b in results]
|
||||||
|
medians = [b["median"] for b in results]
|
||||||
|
|
||||||
|
indices = sorted(range(len(labels)), key=lambda k: medians[k])
|
||||||
|
labels = [labels[i] for i in indices]
|
||||||
|
times = [times[i] for i in indices]
|
||||||
|
|
||||||
boxplot = plt.boxplot(times, vert=True, patch_artist=True)
|
boxplot = plt.boxplot(times, vert=True, patch_artist=True)
|
||||||
cmap = plt.get_cmap("rainbow")
|
cmap = plt.get_cmap("rainbow")
|
||||||
@ -45,6 +50,7 @@ if args.title:
|
|||||||
plt.legend(handles=boxplot["boxes"], labels=labels, loc="best", fontsize="medium")
|
plt.legend(handles=boxplot["boxes"], labels=labels, loc="best", fontsize="medium")
|
||||||
plt.ylabel("Time [s]")
|
plt.ylabel("Time [s]")
|
||||||
plt.ylim(0, None)
|
plt.ylim(0, None)
|
||||||
|
plt.xticks(list(range(1, len(labels)+1)), labels, rotation=45)
|
||||||
if args.output:
|
if args.output:
|
||||||
plt.savefig(args.output)
|
plt.savefig(args.output)
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user