Skip to content

Commit 1b08694

Browse files
committed
chore: improving estimates
1 parent f13922c commit 1b08694

File tree

2 files changed

+91
-10
lines changed

2 files changed

+91
-10
lines changed

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ The table below shows realistic scenarios:
153153
| 1‑6 | 31 s | 30 s | 30 s | 2 min 19 s | 3 min 27 s |
154154
| 7 | 2 min 4 s | 30 s | 30 s | 2 min 19 s | 3 min 27 s |
155155
| 8 | 4 min 8 s | 30 s | 30 s | 2 min 19 s | 3 min 27 s |
156-
| 9 | 8 min 15 s | 30 s | 30 s | 2 min 19 s | 3 min 27 s |
156+
| 9 | 8 min 0 s | 30 s | 30 s | 2 min 19 s | 3 min 27 s |
157157
| 10 | 16 min 30 s | 30 s | 31 s | 2 min 23 s | 3 min 33 s |
158158
| 11 | 33 min 1 s | 30 s | 35 s | 2 min 41 s | 4 min 1 s |
159159
| 12 | 1 h 6 min | 30 s | 47 s | 3 min 36 s | 5 min 24 s |
@@ -164,14 +164,14 @@ The table below shows realistic scenarios:
164164
| 17 | 1 d 11 h | 16 min 0 s | 16 min 19 s | 1 h 15 m | 1 h 52 m |
165165
| 18 | 2 d 22 h | 32 min 0 s | 32 min 20 s | 2 h 29 m | 3 h 43 m |
166166
| 19 | 5 d 21 h | 1 h 4 m | 1 h 4 m | 4 h 55 m | 7 h 22 m |
167-
| 20 | 11 d 18 h | 2 h 8 m | 2 h 8 m | 9 h 52 m | 14 h 48 m |
167+
| 20 | 11 d 9 h | 2 h 8 m | 2 h 8 m | 9 h 52 m | 14 h 48 m |
168168
| 21 | 23 d 11 h | 4 h 16 m | 4 h 16 m | 19 h 44 m | 1 d 5 h |
169169
| 22 | 46 d 23 h | 8 h 32 m | 8 h 32 m | 1 d 15 h | 2 d 11 h |
170-
| 23 | 93 d 22 h | 17 h 4 m | 17 h 4 m | 3 d 6 h | 4 d 21 h |
171-
| 24 | 187 d 19 h | 1 d 10 h | 1 d 10 h | 6 d 13 h | 9 d 18 h |
172-
| 25 | 1 y 10 d | 2 d 20 h | 2 d 20 h | 13 d 2 h | 19 d 12 h |
173-
| 26 | 2 y 21 d | 5 d 16 h | 5 d 16 h | 26 d 1 h | 39 d 1 h |
174-
| 27 | 4 y 41 d | 11 d 9 h | 11 d 9 h | 52 d 4 h | 78 d 6 h |
170+
| 23 | 91 d 1 h | 17 h 4 m | 17 h 4 m | 3 d 6 h | 4 d 21 h |
171+
| 24 | 182 d 1 h | 1 d 10 h | 1 d 10 h | 6 d 13 h | 9 d 18 h |
172+
| 25 | 364 d 2 h | 2 d 20 h | 2 d 20 h | 13 d 2 h | 19 d 12 h |
173+
| 26 | 728 d 4 h | 5 d 17 h | 5 d 17 h | 26 d 1 h | 39 d 1 h |
174+
| 27 | 1456 d 8 h | 11 d 9 h | 11 d 9 h | 52 d 4 h | 78 d 6 h |
175175
| 28 | 8 y 83 d | 22 d 18 h | 22 d 18 h | 104 d 8 h | 156 d 12 h |
176176
| 29 | 16 y 165 d | 45 d 12 h | 45 d 12 h | 208 d 16 h | 312 d 24 h |
177177
| 30 | 32 y 331 d | 91 d | 91 d | 417 d 8 h | 1 y 261 d |
@@ -194,11 +194,11 @@ For planning purposes, consider the 99th percentile times shown in the table abo
194194

195195
**Interpretation**
196196

197-
* **Single machine (16 threads)**: Systematic search partitions the space among threads, eliminating duplicates. Each thread searches a distinct range, guaranteeing the key will be found after searching exactly half the total space on average.
197+
* **Single machine (16 threads)**: Systematic search partitions the space evenly among threads, eliminating duplicate work. Each thread searches 1/16th of the total space. The expected time to find a key is when half the total space has been searched.
198198

199-
* **Cluster (2048 threads)**: Random search where each machine independently selects candidates. The 128× increase in threads (2048 vs 16) compensates for occasional duplicate work, resulting in much faster wall-clock time despite the same expected number of trials.
199+
* **Cluster (2048 threads)**: Random search where threads independently select candidates. Despite occasional duplicate work, the 128× increase in threads (2048 vs 16) results in much faster wall-clock time.
200200

201-
* **Key insight**: With equal thread counts, systematic search would complete in half the time of random search due to no duplicates. The table shows different thread counts to reflect realistic deployment scenarios.
201+
* **Key insight**: For the same number of threads, systematic search would complete in half the expected time of random search (due to no duplicates). However, the table compares different thread counts to show realistic deployment scenarios.
202202

203203

204204
### Real world example using the `benchmark` command

wskdf-cli/src/main.rs

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,4 +791,85 @@ mod tests {
791791
);
792792
assert_eq!(benchmark_worst, estimation_result.systematic_worst_secs);
793793
}
794+
795+
#[test]
796+
fn test_readme_table_systematic_values() {
797+
// Test that our calculations match what the current pretty() function outputs
798+
// Note: The README table was manually corrected but pretty() still uses year formatting
799+
800+
// Systematic search (16 threads, 30s per derivation) - testing actual pretty() output
801+
assert_eq!(
802+
pretty(calculate_systematic_times(calculate_search_space(9), 16, 30.0).1),
803+
"8min 0s"
804+
);
805+
assert_eq!(
806+
pretty(calculate_systematic_times(calculate_search_space(20), 16, 30.0).1),
807+
"11d 9h"
808+
);
809+
assert_eq!(
810+
pretty(calculate_systematic_times(calculate_search_space(23), 16, 30.0).1),
811+
"91d 1h"
812+
);
813+
assert_eq!(
814+
pretty(calculate_systematic_times(calculate_search_space(24), 16, 30.0).1),
815+
"182d 1h"
816+
);
817+
assert_eq!(
818+
pretty(calculate_systematic_times(calculate_search_space(25), 16, 30.0).1),
819+
"364d 2h"
820+
);
821+
assert_eq!(
822+
pretty(calculate_systematic_times(calculate_search_space(26), 16, 30.0).1),
823+
"1y 363d"
824+
); // Current pretty() output
825+
assert_eq!(
826+
pretty(calculate_systematic_times(calculate_search_space(27), 16, 30.0).1),
827+
"3y 361d"
828+
); // Current pretty() output
829+
}
830+
831+
#[test]
832+
fn test_readme_table_random_values() {
833+
// Test random search values (2048 threads, 30s per derivation) - testing actual pretty() output
834+
assert_eq!(
835+
pretty(calculate_random_times(calculate_search_space(20), 2048, 30.0).0),
836+
"2h 8min"
837+
);
838+
assert_eq!(
839+
pretty(calculate_random_times(calculate_search_space(23), 2048, 30.0).0),
840+
"17h 4min"
841+
);
842+
assert_eq!(
843+
pretty(calculate_random_times(calculate_search_space(24), 2048, 30.0).0),
844+
"1d 10h"
845+
);
846+
assert_eq!(
847+
pretty(calculate_random_times(calculate_search_space(25), 2048, 30.0).0),
848+
"2d 20h"
849+
);
850+
assert_eq!(
851+
pretty(calculate_random_times(calculate_search_space(26), 2048, 30.0).0),
852+
"5d 17h"
853+
); // Actual output (slight rounding difference)
854+
assert_eq!(
855+
pretty(calculate_random_times(calculate_search_space(27), 2048, 30.0).0),
856+
"11d 9h"
857+
);
858+
}
859+
860+
#[test]
861+
fn test_calculation_accuracy() {
862+
// Test that the raw calculations are mathematically correct
863+
// These verify the actual seconds are correct, regardless of formatting
864+
865+
// 20-bit systematic search (16 threads, 30s): 2^19 / 16 * 30 = 983040 seconds = 11d 9h exactly
866+
let (_, systematic_worst_20) =
867+
calculate_systematic_times(calculate_search_space(20), 16, 30.0);
868+
assert_eq!(systematic_worst_20, 983040.0); // 11 days 9 hours in seconds
869+
870+
// 20-bit random search (2048 threads, 30s): 2^19 / 2048 * 30 = 7680 seconds = 2h 8min exactly
871+
let (random_expected_20, _, _) =
872+
calculate_random_times(calculate_search_space(20), 2048, 30.0);
873+
assert_eq!(random_expected_20, 7680.0); // 2 hours 8 minutes in seconds
874+
}
794875
}

0 commit comments

Comments
 (0)