File: compare_json.d

package info (click to toggle)
sambamba 1.0.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,900 kB
  • sloc: javascript: 552; sh: 220; python: 166; ruby: 147; makefile: 104; lisp: 85
file content (33 lines) | stat: -rw-r--r-- 564 bytes parent folder | download
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
30
31
32
33
// Written in the D programming language.

/**
 * Compares std.json
 */

import std.datetime;
import std.json;
import std.stdio;

import msgpack;


void main()
{
    JSONValue jsonObj = parseJSON(`[12, "foo", true, 0.23, {"1":1}, [1, 2]]`);

    void f1()
    {
        parseJSON(toJSON(jsonObj));
    }

    Value mpObj = unpack(pack(12, "foo", true, 0.23, ["1":1], [1, 2]));

    void f2()
    {
        unpack(pack(mpObj));
    }

    auto times = benchmark!(f1, f2)(10000);
    writeln("JSON:    ", times[0].msecs);
    writeln("Msgpack: ", times[1].msecs);
}