Skip to content

Commit 2bca101

Browse files
committed
samples: bench: Reduce benchmark iterations
Drop the iterations so not as much time is spent in CI. This still gives meaning functional results for CI, and the increased value can be used for actual benchmarking. Signed-off-by: David Brown <[email protected]>
1 parent 52cd270 commit 2bca101

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

samples/bench/src/lib.rs

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ const THREAD_STACK_SIZE: usize = 2048;
4242
/// Stack size to use for the work queue.
4343
const WORK_STACK_SIZE: usize = 2048;
4444

45+
/// This is a global iteration. Small numbers still test functionality within CI, and large numbers
46+
/// give more meaningful benchmark results.
47+
const TOTAL_ITERS: usize = 1_000;
48+
// const TOTAL_ITERS: usize = 10_000;
49+
4550
#[no_mangle]
4651
extern "C" fn rust_main() {
4752
let tester = ThreadTests::new(NUM_THREADS);
@@ -54,33 +59,33 @@ extern "C" fn rust_main() {
5459
let simple = Simple::new(tester.workq.clone());
5560
let mut num = 6;
5661
while num < 500 {
57-
simple.run(num, 10_000 / num);
62+
simple.run(num, TOTAL_ITERS / num);
5863
num = num * 13 / 10;
5964
}
6065

6166
tester.run(Command::Empty);
62-
tester.run(Command::SimpleSem(10_000));
63-
tester.run(Command::SimpleSemAsync(10_000));
64-
tester.run(Command::SimpleSemYield(10_000));
65-
tester.run(Command::SimpleSemYieldAsync(10_000));
66-
tester.run(Command::SemWait(10_000));
67-
tester.run(Command::SemWaitAsync(10_000));
68-
tester.run(Command::SemWaitSameAsync(10_000));
69-
tester.run(Command::SemHigh(10_000));
70-
tester.run(Command::SemPingPong(10_000));
71-
tester.run(Command::SemPingPongAsync(10_000));
72-
tester.run(Command::SemOnePingPong(10_000));
67+
tester.run(Command::SimpleSem(TOTAL_ITERS));
68+
tester.run(Command::SimpleSemAsync(TOTAL_ITERS));
69+
tester.run(Command::SimpleSemYield(TOTAL_ITERS));
70+
tester.run(Command::SimpleSemYieldAsync(TOTAL_ITERS));
71+
tester.run(Command::SemWait(TOTAL_ITERS));
72+
tester.run(Command::SemWaitAsync(TOTAL_ITERS));
73+
tester.run(Command::SemWaitSameAsync(TOTAL_ITERS));
74+
tester.run(Command::SemHigh(TOTAL_ITERS));
75+
tester.run(Command::SemPingPong(TOTAL_ITERS));
76+
tester.run(Command::SemPingPongAsync(TOTAL_ITERS));
77+
tester.run(Command::SemOnePingPong(TOTAL_ITERS));
7378
/*
74-
tester.run(Command::SemOnePingPongAsync(NUM_THREADS, 10_000 / 6));
75-
tester.run(Command::SemOnePingPongAsync(20, 10_000 / 20));
76-
tester.run(Command::SemOnePingPongAsync(50, 10_000 / 50));
77-
tester.run(Command::SemOnePingPongAsync(100, 10_000 / 100));
78-
tester.run(Command::SemOnePingPongAsync(500, 10_000 / 500));
79+
tester.run(Command::SemOnePingPongAsync(NUM_THREADS, TOTAL_ITERS / 6));
80+
tester.run(Command::SemOnePingPongAsync(20, TOTAL_ITERS / 20));
81+
tester.run(Command::SemOnePingPongAsync(50, TOTAL_ITERS / 50));
82+
tester.run(Command::SemOnePingPongAsync(100, TOTAL_ITERS / 100));
83+
tester.run(Command::SemOnePingPongAsync(500, TOTAL_ITERS / 500));
7984
tester.run(Command::Empty);
8085
*/
8186
let mut num = 6;
82-
while num < 500 {
83-
tester.run(Command::SemOnePingPongAsync(num, 10_000 / num));
87+
while num < 100 {
88+
tester.run(Command::SemOnePingPongAsync(num, TOTAL_ITERS / num));
8489
num = num * 13 / 10;
8590
}
8691

@@ -889,8 +894,8 @@ impl Locked {
889894
/// Benchmark the performance of Arc.
890895
fn arc_bench() {
891896
let thing = Arc::new(123);
892-
let timer = BenchTimer::new("Arc clone+drop", 10_000);
893-
for _ in 0..10_000 {
897+
let timer = BenchTimer::new("Arc clone+drop", TOTAL_ITERS);
898+
for _ in 0..TOTAL_ITERS {
894899
let _ = thing.clone();
895900
}
896901
timer.stop();
@@ -900,7 +905,7 @@ fn arc_bench() {
900905
#[inline(never)]
901906
#[no_mangle]
902907
fn spin_bench() {
903-
let iters = 10_000;
908+
let iters = TOTAL_ITERS;
904909
let thing = SpinMutex::new(123);
905910
let timer = BenchTimer::new("SpinMutex lock", iters);
906911
for _ in 0..iters {
@@ -916,7 +921,7 @@ fn spin_bench() {
916921
#[inline(never)]
917922
#[no_mangle]
918923
fn sem_bench() {
919-
let iters = 10_000;
924+
let iters = TOTAL_ITERS;
920925
let sem = Semaphore::new(iters as u32, iters as u32);
921926
let timer = BenchTimer::new("Semaphore take", iters);
922927
for _ in 0..iters {

0 commit comments

Comments
 (0)