Skip to content

Commit

Permalink
Add benches for editing the Cvars struct
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-t committed May 25, 2023
1 parent db069db commit 9126c9f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
23 changes: 21 additions & 2 deletions cvars-bench-compile-time/bench.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,25 @@ cargo build --features nomacro,cvars-100
# Hyperfine supports multiple benchmarks in one command and a cleanup command
# but let's keep everything separate so we can comment some benches out
# and so we can easily copy-paste the commands to run them manually.

# TODO 10k cvars take several minutes, uncomment benchmarks when this is fixed.
# LATER 10k,nomacro takes 8s but 10k,derive-dummy only takes 2s - why?

# Measure incremental rebuild time after editing the Cvars struct.
hyperfine --warmup 2 "sed --in-place 's/test0/test0a/' src/derive-100.in && cargo build --features nomacro,cvars-100"
hyperfine --warmup 2 "sed --in-place 's/test0/test0a/' src/derive-1000.in && cargo build --features nomacro,cvars-1000"
hyperfine --warmup 2 "sed --in-place 's/test0/test0a/' src/derive-10000.in && cargo build --features nomacro,cvars-10000"
hyperfine --warmup 2 "sed --in-place 's/test0/test0a/' src/derive-100.in && cargo build --features derive-dummy,cvars-100"
hyperfine --warmup 2 "sed --in-place 's/test0/test0a/' src/derive-1000.in && cargo build --features derive-dummy,cvars-1000"
hyperfine --warmup 2 "sed --in-place 's/test0/test0a/' src/derive-10000.in && cargo build --features derive-dummy,cvars-10000"
hyperfine --warmup 2 "sed --in-place 's/test0/test0a/' src/derive-100.in && cargo build --features derive,cvars-100"
hyperfine --warmup 2 "sed --in-place 's/test0/test0a/' src/derive-1000.in && cargo build --features derive,cvars-1000"
#hyperfine --warmup 2 "sed --in-place 's/test0/test0a/' src/derive-10000.in && cargo build --features derive,cvars-10000"
hyperfine --warmup 2 "sed --in-place 's/test0/test0a/' src/fnlike-100.in && cargo build --features fnlike,cvars-100"
hyperfine --warmup 2 "sed --in-place 's/test0/test0a/' src/fnlike-1000.in && cargo build --features fnlike,cvars-1000"
#hyperfine --warmup 2 "sed --in-place 's/test0/test0a/' src/fnlike-10000.in && cargo build --features fnlike,cvars-10000"

# Measure incremental rebuild time after editing main.rs.
hyperfine --warmup 2 "echo '// test' >> src/main.rs && cargo build --features nomacro,cvars-100"
hyperfine --warmup 2 "echo '// test' >> src/main.rs && cargo build --features nomacro,cvars-1000"
hyperfine --warmup 2 "echo '// test' >> src/main.rs && cargo build --features nomacro,cvars-10000"
Expand All @@ -19,9 +38,9 @@ hyperfine --warmup 2 "echo '// test' >> src/main.rs && cargo build --features de
hyperfine --warmup 2 "echo '// test' >> src/main.rs && cargo build --features derive-dummy,cvars-10000"
hyperfine --warmup 2 "echo '// test' >> src/main.rs && cargo build --features derive,cvars-100"
hyperfine --warmup 2 "echo '// test' >> src/main.rs && cargo build --features derive,cvars-1000"
#hyperfine --warmup 2 "echo '// test' >> src/main.rs && cargo build --features derive,cvars-10000" # TODO this gets stuck
#hyperfine --warmup 2 "echo '// test' >> src/main.rs && cargo build --features derive,cvars-10000"
hyperfine --warmup 2 "echo '// test' >> src/main.rs && cargo build --features fnlike,cvars-100"
hyperfine --warmup 2 "echo '// test' >> src/main.rs && cargo build --features fnlike,cvars-1000"
#hyperfine --warmup 2 "echo '// test' >> src/main.rs && cargo build --features fnlike,cvars-10000" # TODO this gets stuck
#hyperfine --warmup 2 "echo '// test' >> src/main.rs && cargo build --features fnlike,cvars-10000"

./cleanup.sh
2 changes: 2 additions & 0 deletions cvars-bench-compile-time/cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
# Cleanup after running the benchmarks.
# This is a separate script for convenience.

sed --in-place 's/test0a*/test0/' src/*.in

grep --invert-match '^// test$' src/main.rs > src/main.rs.tmp
mv src/main.rs.tmp src/main.rs
5 changes: 3 additions & 2 deletions cvars-bench-compile-time/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ mod bench {

impl Cvars {
pub fn get_string(&self, _cvar_name: &str) -> Result<String, String> {
Ok("nomacro".to_string())
Ok(self.test1.to_string())
}
pub fn set_str(&mut self, _cvar_name: &str, _str_value: &str) -> Result<(), String> {
pub fn set_str(&mut self, _cvar_name: &str, str_value: &str) -> Result<(), String> {
self.test1 = str_value.parse().unwrap();
Ok(())
}
}
Expand Down

0 comments on commit 9126c9f

Please sign in to comment.