forked from thecaliskan/laravel-benchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
json.lua
29 lines (28 loc) · 1.39 KB
/
json.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
-- example reporting script which demonstrates a custom
-- done() function that prints results as JSON
done = function(summary, latency, requests)
io.write("\nJSON Output:\n")
io.write("{\n")
io.write(string.format("\t\"requests\": %d,\n", summary.requests))
io.write(string.format("\t\"duration_in_microseconds\": %0.2f,\n", summary.duration))
io.write(string.format("\t\"bytes\": %d,\n", summary.bytes))
io.write(string.format("\t\"requests_per_sec\": %0.2f,\n", (summary.requests/summary.duration)*1e6))
io.write(string.format("\t\"bytes_transfer_per_sec\": %0.2f,\n", (summary.bytes/summary.duration)*1e6))
io.write(string.format("\t\"connect_errors\": %d,\n", summary.errors.connect))
io.write(string.format("\t\"read_errors\": %d,\n", summary.errors.read))
io.write(string.format("\t\"write_errors\": %d,\n", summary.errors.write))
io.write(string.format("\t\"http_errors\": %d,\n", summary.errors.status))
io.write(string.format("\t\"timeouts\": %d,\n", summary.errors.timeout))
io.write("\t\"latency_distributions\": [\n")
for _, p in pairs({ 50, 75, 90, 99, 99.99 }) do
io.write("\t\t{\n")
n = latency:percentile(p)
io.write(string.format("\t\t\t\"percentile\": %g,\n\t\t\t\"latency_in_microseconds\": %d\n", p, n))
if p == 99.99 then
io.write("\t\t}\n")
else
io.write("\t\t},\n")
end
end
io.write("\t]\n}\n")
end