-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #5 --------- Signed-off-by: Tony Gorez <[email protected]>
- Loading branch information
Showing
6 changed files
with
398 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
/dist | ||
/node_modules | ||
/implementations/boon/target/ | ||
/.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} |
Oops, something went wrong.