From 11c5ab4d0c369400d5a1360df81e49fa74da49ca Mon Sep 17 00:00:00 2001
From: Xavier L'Heureux <xavier.lheureux@icloud.com>
Date: Fri, 15 Mar 2019 15:43:26 -0400
Subject: [PATCH] Fix the benchmark

Move the test to its own file
Copy 3 times the same program to better evaluate efficiency
Don't use `println`: buffering skews the benchmark
---
 benches/terminator.rs | 35 +++++++++++++++++------------------
 1 file changed, 17 insertions(+), 18 deletions(-)

diff --git a/benches/terminator.rs b/benches/terminator.rs
index 5442a0e9..d1cde0f2 100644
--- a/benches/terminator.rs
+++ b/benches/terminator.rs
@@ -1,30 +1,29 @@
 #[macro_use]
 extern crate criterion;
 
-use criterion::Criterion;
+use criterion::*;
 use ion_shell::parser::Terminator;
 
 const TEXT: &str = include_str!("test.ion");
 const EOF: &str = include_str!("herestring.ion");
 
 fn criterion_benchmark(c: &mut Criterion) {
-    c.bench_function("terminator", |b| {
-        b.iter(|| {
-            let mut bytes = TEXT.bytes().peekable();
-            while bytes.peek().is_some() {
-                let stmt = Terminator::new(&mut bytes).terminate();
-            }
-        })
-    });
-
-    c.bench_function("terminator EOF", |b| {
-        b.iter(|| {
-            let mut bytes = EOF.bytes().peekable();
-            while bytes.peek().is_some() {
-                let stmt = Terminator::new(&mut bytes).terminate();
-            }
-        })
-    });
+    c.bench(
+        "terminator-throughput",
+        ParameterizedBenchmark::new(
+            "terminator",
+            |b, script| {
+                b.iter(|| {
+                    let mut bytes = script.bytes().peekable();
+                    while bytes.peek().is_some() {
+                        let stmt = Terminator::new(&mut bytes).terminate();
+                    }
+                })
+            },
+            vec![TEXT, EOF],
+        )
+        .throughput(|script| Throughput::Bytes(script.len() as u32)),
+    );
 }
 
 criterion_group!(benches, criterion_benchmark);
-- 
GitLab