summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2021-06-18 21:40:28 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2021-06-18 21:40:28 +0100
commitea15a22b8460d1ee4d96b81193c947640a6d1162 (patch)
treeaa9fcb03f33768798b5f5738a09efb0f5f5210bb /tests
parent0bd23ee772aa12dfbcccba29fe3ebb226be639d1 (diff)
downloadsubplot-ea15a22b8460d1ee4d96b81193c947640a6d1162.tar.gz
tests: Move bindings microbenchmark to an integration test
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/bindings-ubm.rs55
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/bindings-ubm.rs b/tests/bindings-ubm.rs
new file mode 100644
index 0000000..5e68ac1
--- /dev/null
+++ b/tests/bindings-ubm.rs
@@ -0,0 +1,55 @@
+// A micro-benchmark for the Bindings struct.
+//
+// The goal is to see how it deals with looking up a binding when
+// there are a large number of them.
+
+use regex::RegexBuilder;
+use std::collections::HashMap;
+use std::time::SystemTime;
+use subplot::{Binding, Bindings, ScenarioStep, StepKind};
+
+const N: i32 = 1000;
+
+#[test]
+fn bindings_microbenchmark() {
+ let time = SystemTime::now();
+
+ let mut texts = vec![];
+ for i in 0..N {
+ texts.push(format!("step {}", i));
+ }
+ let texted = time.elapsed().unwrap();
+
+ let mut re = vec![];
+ for t in texts.iter() {
+ re.push((
+ t,
+ RegexBuilder::new(&format!("^{}$", t))
+ .case_insensitive(false)
+ .build()
+ .unwrap(),
+ ));
+ }
+ let regexed = time.elapsed().unwrap();
+
+ let mut toadd = vec![];
+ for t in texts.iter() {
+ toadd.push(Binding::new(StepKind::Given, t, "func", None, false, HashMap::new()).unwrap());
+ }
+ let created = time.elapsed().unwrap();
+
+ let mut bindings = Bindings::new();
+ for binding in toadd {
+ bindings.add(binding);
+ }
+ let added = time.elapsed().unwrap();
+ let step = ScenarioStep::new(StepKind::Given, "given", &format!("step {}", N - 1));
+ bindings.find(&step).unwrap();
+ let found = time.elapsed().unwrap();
+
+ println!("texted: {}", texted.as_millis());
+ println!("regexed: {}", regexed.as_millis());
+ println!("created: {}", created.as_millis());
+ println!("added: {}", added.as_millis());
+ println!("found: {}", found.as_millis());
+}