bench.lua 737 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/env lua
  2. -- Simple JSON benchmark.
  3. --
  4. -- Your Mileage May Vary.
  5. --
  6. -- Mark Pulford <[email protected]>
  7. require "common"
  8. local json = require "cjson"
  9. function bench_file(filename)
  10. local data_json = file_load(filename)
  11. local data_obj = json.decode(data_json)
  12. local function test_encode ()
  13. json.encode(data_obj)
  14. end
  15. local function test_decode ()
  16. json.decode(data_json)
  17. end
  18. local tests = {
  19. encode = test_encode,
  20. decode = test_decode
  21. }
  22. return benchmark(tests, 5000, 5)
  23. end
  24. for i = 1, #arg do
  25. local results = bench_file(arg[i])
  26. for k, v in pairs(results) do
  27. print(string.format("%s: %s: %d", arg[i], k, v))
  28. end
  29. end
  30. -- vi:ai et sw=4 ts=4: