diff --git a/bench/twitter/.gitignore b/bench/twitter/.gitignore new file mode 100644 index 0000000..afa0c42 --- /dev/null +++ b/bench/twitter/.gitignore @@ -0,0 +1,4 @@ +simdjson-twitterbench +simdjson.cpp +simdjson.h +twitter.json \ No newline at end of file diff --git a/bench/twitter/main.cpp b/bench/twitter/main.cpp new file mode 100644 index 0000000..a1e9c09 --- /dev/null +++ b/bench/twitter/main.cpp @@ -0,0 +1,28 @@ +#include "simdjson.h" +using namespace simdjson; +int main(int argc, char** argv) { + if(argc != 2) { + std::cout << "USAGE: ./simdjson " << std::endl; + exit(1); + } + dom::parser parser; + try + { + const dom::element doc = parser.load(argv[1]); + int i = 0; + for(auto status: doc["statuses"]) { + // std::cout << status["id"] << '\n'; + i += 1; + } + if(i != 100) { + std::cout << "error. expected i=100. found i=" << i << '\n'; + return 1; + } + } + catch(const std::exception& e) + { + std::cerr << e.what() << '\n'; + return 1; + } + return 0; +} diff --git a/bench/twitter/main.zig b/bench/twitter/main.zig new file mode 100644 index 0000000..3ca686a --- /dev/null +++ b/bench/twitter/main.zig @@ -0,0 +1,33 @@ +const std = @import("std"); +const dom = @import("simdjzon").dom; + +pub fn main() !u8 { + var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); + defer arena.deinit(); + const allocator = arena.allocator(); + const args = try std.process.argsAlloc(allocator); + if(args.len != 2) { + std.debug.print("USAGE: ./simdjson \n", .{}); + } + var parser = try dom.Parser.initFile(allocator, args[1], .{}); + defer parser.deinit(); + parser.parse() catch |err| { + std.log.err("parse failed. {s}", .{@errorName(err)}); + return 1; + }; + const statuses = try parser.element().at_pointer("/statuses"); + const array = try statuses.get_array(); + var i: usize = 0; + while(array.at(i)) |status| : (i += 1) { + _ = status; // autofix + // const id = try status.at_pointer("/id"); + // std.debug.print("{}\n", .{try id.get_int64()}); + } + // std.debug.print("i={}\n", .{i}); + if (i != 100) { + std.debug.print("error. expected i=100. found i={}\n", .{i}); + return 1; + } + + return 0; +} \ No newline at end of file diff --git a/bench/twitter/run.sh b/bench/twitter/run.sh new file mode 100755 index 0000000..7714c1f --- /dev/null +++ b/bench/twitter/run.sh @@ -0,0 +1,19 @@ +#!/bin/bash +set -xe + +rm -f simdjson.cpp simdjson.h twitter.json simdjson-twitterbench + +# build simdjzon +zig version +zig build -Doptimize=ReleaseFast + +# build simdjson +g++ --version +cat bench/twitter/main.cpp +wget https://github.com/simdjson/simdjson/raw/master/singleheader/simdjson.cpp -O bench/twitter/simdjson.cpp +wget https://github.com/simdjson/simdjson/raw/master/singleheader/simdjson.h -O bench/twitter/simdjson.h +wget https://github.com/simdjson/simdjson/raw/master/jsonexamples/twitter.json -O bench/twitter/twitter.json +g++ bench/twitter/main.cpp bench/twitter/simdjson.cpp -Ibench/twitter -o bench/twitter/simdjson-twitterbench -O3 -march=native + +# bench +poop "./bench/twitter/simdjson-twitterbench bench/twitter/twitter.json" "zig-out/bin/twitterbench bench/twitter/twitter.json" diff --git a/build.zig b/build.zig index ef26518..29be7cc 100644 --- a/build.zig +++ b/build.zig @@ -71,4 +71,18 @@ pub fn build(b: *std.Build) void { const run_step = b.step("run", "Run the app"); run_step.dependOn(&run_cmd.step); + + const twitterbench = b.addExecutable(.{ + .name = "twitterbench", + .root_source_file = .{ .path = "bench/twitter/main.zig" }, + .target = target, + .optimize = optimize, + }); + twitterbench.root_module.addImport("simdjzon", mod); + b.installArtifact(twitterbench); + const run_twitter_bench = b.addRunArtifact(twitterbench); + if (b.args) |args| run_twitter_bench.addArgs(args); + const run_twitter_bench_step = b.step("twitter-bench", "Run the twitter-bench"); + run_twitter_bench_step.dependOn(&run_twitter_bench.step); + }