Skip to content

Commit

Permalink
benchmark: add boon (#11)
Browse files Browse the repository at this point in the history
Fix #5

---------

Signed-off-by: Tony Gorez <[email protected]>
  • Loading branch information
tony-go authored Aug 28, 2024
1 parent fbaa073 commit 0705963
Show file tree
Hide file tree
Showing 6 changed files with 398 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/dist
/node_modules
/implementations/boon/target/
/.DS_Store
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,14 @@ dist/results/ajv/%: \
node_modules \
| dist/results/ajv
node $< $(word 2,$^) $(word 3,$^) > $@

# BOON

dist/results/boon/%: \
implementations/boon/src/main.rs \
implementations/boon/Cargo.toml \
schemas/%/schema.json \
schemas/%/instances.jsonl \
| dist/results/boon
cargo run --manifest-path implementations/boon/Cargo.toml --release $(dir $(word 3,$^)) > $@

323 changes: 323 additions & 0 deletions implementations/boon/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions implementations/boon/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "boon_benchmark"
version = "0.1.0"
edition = "2021"

[dependencies]
boon = "0.6"
serde = "1"
serde_json = "1"
url = "2"
42 changes: 42 additions & 0 deletions implementations/boon/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use std::{error::Error, fs::File, io::{BufReader, BufRead}, time::Instant};
use boon::{Compiler, Schemas};
use serde_json::Value;
use std::env;

fn main() -> Result<(), Box<dyn Error>> {
// Get arguments
let args: Vec<String> = env::args().collect();
let example_folder = &args[1];

// Get the schema and instance paths
let schema_file = std::fs::canonicalize(example_folder.to_owned() + "/schema.json")?;
let instance_file = std::fs::canonicalize(example_folder.to_owned() + "/instances.jsonl")?;

// Read the instance file
let file = File::open(&instance_file)?;
let reader = BufReader::new(file);

// Compile the schema
let mut schemas = Schemas::new();
let mut compiler = Compiler::new();
let sch_index = compiler.compile(schema_file.to_str().ok_or("NULL")?, &mut schemas)?;

// Serialize instance lines
let mut serde_lines = std::vec::Vec::new();
for line in reader.lines() {
let line = line?;
let instance: Value = serde_json::from_str(&line)?;
serde_lines.push(instance);
}

// Validate the instances
let start = Instant::now();
for line in serde_lines {
let result = schemas.validate(&line, sch_index);
assert!(result.is_ok(), "Validation failed for line: {}", line);
}
let duration = start.elapsed().as_nanos();
println!("{:?}", duration);

Ok(())
}
Loading

0 comments on commit 0705963

Please sign in to comment.