diff options
Diffstat (limited to '')
| -rwxr-xr-x | tests/bench.lua | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/bench.lua b/tests/bench.lua new file mode 100755 index 0000000..b5b1a77 --- /dev/null +++ b/tests/bench.lua | |||
| @@ -0,0 +1,39 @@ | |||
| 1 | #!/usr/bin/env lua | ||
| 2 | |||
| 3 | -- Simple JSON benchmark. | ||
| 4 | -- | ||
| 5 | -- Your Mileage May Vary. | ||
| 6 | |||
| 7 | require "common" | ||
| 8 | local json = require "cjson" | ||
| 9 | --local json = require "json" | ||
| 10 | --local json = require "dkjson" | ||
| 11 | |||
| 12 | function bench_file(filename) | ||
| 13 | local data_json = file_load(filename) | ||
| 14 | local data_obj = json.decode(data_json) | ||
| 15 | |||
| 16 | local function test_encode () | ||
| 17 | json.encode(data_obj) | ||
| 18 | end | ||
| 19 | local function test_decode () | ||
| 20 | json.decode(data_json) | ||
| 21 | end | ||
| 22 | |||
| 23 | local tests = { | ||
| 24 | encode = test_encode, | ||
| 25 | decode = test_decode | ||
| 26 | } | ||
| 27 | |||
| 28 | return benchmark(tests, 5000, 5) | ||
| 29 | end | ||
| 30 | |||
| 31 | i = 1 | ||
| 32 | while arg[i] do | ||
| 33 | local results = {} | ||
| 34 | results[arg[i]] = bench_file(arg[i]) | ||
| 35 | dump_value(results) | ||
| 36 | i = i + 1 | ||
| 37 | end | ||
| 38 | |||
| 39 | -- vi:ai et sw=4 ts=4: | ||
