|
1 |
| -use criterion::{black_box, criterion_group, criterion_main, Criterion}; |
2 |
| - |
3 |
| -fn uri_sqlite() -> String { |
4 |
| - format!( |
5 |
| - "sqlite://{}/tests/db/sqlite/complex_sample.gnucash?mode=ro", |
6 |
| - env!("CARGO_MANIFEST_DIR") |
7 |
| - ) |
8 |
| -} |
9 |
| - |
10 |
| -fn uri_xml() -> String { |
11 |
| - format!( |
12 |
| - "{}/tests/db/xml/complex_sample.gnucash", |
13 |
| - env!("CARGO_MANIFEST_DIR") |
14 |
| - ) |
15 |
| -} |
16 |
| - |
17 |
| -fn benchmark_sql_query(c: &mut Criterion) { |
18 |
| - let rt = tokio::runtime::Runtime::new().unwrap(); |
19 |
| - let book = rt.block_on(async { |
20 |
| - let query = rucash::SQLiteQuery::new(&uri_sqlite()).await.unwrap(); |
21 |
| - rucash::Book::new(query).await.unwrap() |
22 |
| - }); |
23 |
| - |
24 |
| - c.bench_function("sql query", |b| { |
25 |
| - b.to_async(&rt).iter(|| async { |
26 |
| - book.accounts_contains_name_ignore_case(black_box("aS")) |
27 |
| - .await |
28 |
| - }); |
29 |
| - }); |
30 |
| -} |
31 |
| - |
32 |
| -fn benchmark_vec_filter(c: &mut Criterion) { |
33 |
| - let rt = tokio::runtime::Runtime::new().unwrap(); |
34 |
| - let book = rt.block_on(async { |
35 |
| - let query = rucash::SQLiteQuery::new(&uri_sqlite()).await.unwrap(); |
36 |
| - rucash::Book::new(query).await.unwrap() |
37 |
| - }); |
38 |
| - |
39 |
| - c.bench_function("vec filter", |b| { |
40 |
| - b.to_async(&rt).iter(|| async { |
41 |
| - let vec = book.accounts().await.unwrap(); |
42 |
| - let _: Vec<_> = vec |
43 |
| - .into_iter() |
44 |
| - .filter(|x| x.name.to_lowercase().contains(black_box("aS"))) |
45 |
| - .collect(); |
46 |
| - }) |
47 |
| - }); |
48 |
| -} |
49 |
| - |
50 |
| -fn benchmark_xml_book(c: &mut Criterion) { |
51 |
| - let rt = tokio::runtime::Runtime::new().unwrap(); |
52 |
| - let book = rt.block_on(async { |
53 |
| - let query = rucash::XMLQuery::new(&uri_xml()).unwrap(); |
54 |
| - rucash::Book::new(query).await.unwrap() |
55 |
| - }); |
56 |
| - |
57 |
| - c.bench_function("XMLBook", |b| { |
58 |
| - b.to_async(&rt).iter(|| async { book.accounts().await }) |
59 |
| - }); |
60 |
| -} |
61 |
| - |
62 |
| -fn benchmark_sqlite_book(c: &mut Criterion) { |
63 |
| - let rt = tokio::runtime::Runtime::new().unwrap(); |
64 |
| - let book = rt.block_on(async { |
65 |
| - let query = rucash::SQLiteQuery::new(&uri_sqlite()).await.unwrap(); |
66 |
| - rucash::Book::new(query).await.unwrap() |
67 |
| - }); |
68 |
| - |
69 |
| - c.bench_function("SqliteBook", |b| { |
70 |
| - b.to_async(&rt).iter(|| async { book.accounts().await }) |
71 |
| - }); |
72 |
| -} |
73 |
| - |
74 |
| -criterion_group!( |
75 |
| - benches, |
76 |
| - benchmark_sql_query, |
77 |
| - benchmark_vec_filter, |
78 |
| - benchmark_xml_book, |
79 |
| - benchmark_sqlite_book, |
80 |
| -); |
81 |
| -criterion_main!(benches); |
| 1 | +use criterion::{black_box, criterion_group, criterion_main, Criterion}; |
| 2 | + |
| 3 | +fn uri_sqlite() -> String { |
| 4 | + format!( |
| 5 | + "sqlite://{}/tests/db/sqlite/complex_sample.gnucash?mode=ro", |
| 6 | + env!("CARGO_MANIFEST_DIR") |
| 7 | + ) |
| 8 | +} |
| 9 | + |
| 10 | +fn uri_xml() -> String { |
| 11 | + format!( |
| 12 | + "{}/tests/db/xml/complex_sample.gnucash", |
| 13 | + env!("CARGO_MANIFEST_DIR") |
| 14 | + ) |
| 15 | +} |
| 16 | + |
| 17 | +fn uri_sqlitefaster() -> String { |
| 18 | + format!( |
| 19 | + "file:/{}/tests/db/sqlite/complex_sample.gnucash", |
| 20 | + env!("CARGO_MANIFEST_DIR") |
| 21 | + ) |
| 22 | +} |
| 23 | + |
| 24 | +fn benchmark_sql_query(c: &mut Criterion) { |
| 25 | + let rt = tokio::runtime::Runtime::new().unwrap(); |
| 26 | + let book = rt.block_on(async { |
| 27 | + let query = rucash::SQLiteQuery::new(&uri_sqlite()).await.unwrap(); |
| 28 | + rucash::Book::new(query).await.unwrap() |
| 29 | + }); |
| 30 | + |
| 31 | + c.bench_function("sql query", |b| { |
| 32 | + b.to_async(&rt).iter(|| async { |
| 33 | + book.accounts_contains_name_ignore_case(black_box("aS")) |
| 34 | + .await |
| 35 | + }); |
| 36 | + }); |
| 37 | +} |
| 38 | + |
| 39 | +fn benchmark_sql_faster_query(c: &mut Criterion) { |
| 40 | + let rt = tokio::runtime::Runtime::new().unwrap(); |
| 41 | + let book = rt.block_on(async { |
| 42 | + let query = rucash::SQLiteQueryFaster::new(&uri_sqlitefaster()).unwrap(); |
| 43 | + rucash::Book::new(query).await.unwrap() |
| 44 | + }); |
| 45 | + |
| 46 | + c.bench_function("sql faster query", |b| { |
| 47 | + b.to_async(&rt).iter(|| async { |
| 48 | + book.accounts_contains_name_ignore_case(black_box("aS")) |
| 49 | + .await |
| 50 | + }); |
| 51 | + }); |
| 52 | +} |
| 53 | + |
| 54 | +fn benchmark_vec_filter(c: &mut Criterion) { |
| 55 | + let rt = tokio::runtime::Runtime::new().unwrap(); |
| 56 | + let book = rt.block_on(async { |
| 57 | + let query = rucash::SQLiteQuery::new(&uri_sqlite()).await.unwrap(); |
| 58 | + rucash::Book::new(query).await.unwrap() |
| 59 | + }); |
| 60 | + |
| 61 | + c.bench_function("vec filter", |b| { |
| 62 | + b.to_async(&rt).iter(|| async { |
| 63 | + let vec = book.accounts().await.unwrap(); |
| 64 | + let _: Vec<_> = vec |
| 65 | + .into_iter() |
| 66 | + .filter(|x| x.name.to_lowercase().contains(black_box("aS"))) |
| 67 | + .collect(); |
| 68 | + }) |
| 69 | + }); |
| 70 | +} |
| 71 | + |
| 72 | +fn benchmark_xml_book(c: &mut Criterion) { |
| 73 | + let rt = tokio::runtime::Runtime::new().unwrap(); |
| 74 | + let book = rt.block_on(async { |
| 75 | + let query = rucash::XMLQuery::new(&uri_xml()).unwrap(); |
| 76 | + rucash::Book::new(query).await.unwrap() |
| 77 | + }); |
| 78 | + |
| 79 | + c.bench_function("XMLBook", |b| { |
| 80 | + b.to_async(&rt).iter(|| async { book.accounts().await }) |
| 81 | + }); |
| 82 | +} |
| 83 | + |
| 84 | +fn benchmark_sqlite_book(c: &mut Criterion) { |
| 85 | + let rt = tokio::runtime::Runtime::new().unwrap(); |
| 86 | + let book = rt.block_on(async { |
| 87 | + let query = rucash::SQLiteQuery::new(&uri_sqlite()).await.unwrap(); |
| 88 | + rucash::Book::new(query).await.unwrap() |
| 89 | + }); |
| 90 | + |
| 91 | + c.bench_function("SqliteBook", |b| { |
| 92 | + b.to_async(&rt).iter(|| async { book.accounts().await }) |
| 93 | + }); |
| 94 | +} |
| 95 | + |
| 96 | +fn benchmark_sqlitefaster_book(c: &mut Criterion) { |
| 97 | + let rt = tokio::runtime::Runtime::new().unwrap(); |
| 98 | + let book = rt.block_on(async { |
| 99 | + let query = rucash::SQLiteQueryFaster::new(&uri_sqlitefaster()).unwrap(); |
| 100 | + rucash::Book::new(query).await.unwrap() |
| 101 | + }); |
| 102 | + |
| 103 | + c.bench_function("SqliteFasterBook", |b| { |
| 104 | + b.to_async(&rt).iter(|| async { book.accounts().await }) |
| 105 | + }); |
| 106 | +} |
| 107 | + |
| 108 | +criterion_group!( |
| 109 | + benches, |
| 110 | + benchmark_sql_query, |
| 111 | + benchmark_sql_faster_query, |
| 112 | + benchmark_vec_filter, |
| 113 | + benchmark_xml_book, |
| 114 | + benchmark_sqlite_book, |
| 115 | + benchmark_sqlitefaster_book, |
| 116 | +); |
| 117 | +criterion_main!(benches); |
0 commit comments