-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
41 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion}; | ||
use serde_json::json; | ||
use tailcall::blueprint::DynamicValue; | ||
use tailcall::serde_value_ext::ValueExt; | ||
|
||
struct BenchData { | ||
id: String, | ||
ctx: serde_json::Value, | ||
dynamic_value: DynamicValue, | ||
} | ||
|
||
fn setup() -> Vec<BenchData> { | ||
let mut data = Vec::new(); | ||
let ctx = json!({"user": {"name": "John Doe","details": {"age": 30,"city": "New York"}}}); | ||
let template = json!({"name": "{{jq: .user.name}}"}); | ||
let dynamic_value = DynamicValue::try_from(&template).unwrap(); | ||
data.push(BenchData { id: "t1".to_string(), ctx, dynamic_value }); | ||
|
||
let ctx = json!([{"name": "Alice", "age": 25, "city": "New York"},{"name": "Bob", "age": 30, "city": "Chicago"},{"name": "Sandip", "age": 16, "city": "GoodQuestion"},{"name": "Charlie", "age": 22, "city": "San Francisco"}]); | ||
let template = json!({"a": "{{jq: sort_by(.age) | .[0].name }}"}); | ||
let dynamic_value = DynamicValue::try_from(&template).unwrap(); | ||
data.push(BenchData { id: "t2".to_string(), ctx, dynamic_value }); | ||
|
||
data | ||
} | ||
|
||
fn jq_benchmark(c: &mut Criterion) { | ||
let data = setup(); | ||
for datum in data { | ||
c.bench_with_input(BenchmarkId::new("data", &datum.id), &datum, |b, datum| { | ||
b.iter(|| { | ||
let result = datum.dynamic_value.render_value(&datum.ctx); | ||
black_box(result).unwrap(); | ||
}) | ||
}); | ||
} | ||
} | ||
|
||
criterion_group!(benches, jq_benchmark); | ||
criterion_main!(benches); |
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
6f49c1a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running 30s test @ http://localhost:8000/graphql
4 threads and 100 connections
389596 requests in 30.01s, 1.95GB read
Requests/sec: 12981.19
Transfer/sec: 66.63MB