-
-
Notifications
You must be signed in to change notification settings - Fork 313
/
parallel.rs
122 lines (110 loc) · 3.8 KB
/
parallel.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
mod optimize_chunk_size_and_thread_limit {
use git_features::parallel::optimize_chunk_size_and_thread_limit;
#[test]
fn not_enough_chunks_for_threads() {
assert_eq!(
optimize_chunk_size_and_thread_limit(1, Some(10), None, Some(10)),
(1, Some(5), 5)
);
assert_eq!(
optimize_chunk_size_and_thread_limit(1, Some(10), Some(3), Some(10)),
(1, Some(3), 3),
"the thread limit is always respected"
);
}
#[test]
fn some_more_chunks_per_thread() {
assert_eq!(
optimize_chunk_size_and_thread_limit(1, Some(30), None, Some(10)),
(1, Some(10), 10)
);
assert_eq!(
optimize_chunk_size_and_thread_limit(1, Some(30), Some(5), Some(10)),
(3, Some(5), 5),
"the thread limit is always respected"
);
}
#[test]
fn chunk_size_too_small() {
assert_eq!(
optimize_chunk_size_and_thread_limit(1, Some(100), None, Some(10)),
(5, Some(10), 10)
);
assert_eq!(
optimize_chunk_size_and_thread_limit(1, Some(100), Some(5), Some(10)),
(10, Some(5), 5),
"the thread limit is always respected"
);
}
#[test]
fn chunk_size_too_big() {
assert_eq!(
optimize_chunk_size_and_thread_limit(50, Some(100), None, Some(10)),
(5, Some(10), 10)
);
assert_eq!(
optimize_chunk_size_and_thread_limit(50, Some(100), Some(5), Some(10)),
(10, Some(5), 5),
"the thread limit is always respected"
);
}
mod unknown_chunk_count {
use git_features::parallel::optimize_chunk_size_and_thread_limit;
#[test]
fn medium_chunk_size_many_threads() {
assert_eq!(
optimize_chunk_size_and_thread_limit(50, None, None, Some(4)),
(50, Some(4), 4),
"really, what do we know"
);
}
#[test]
fn medium_chunk_size_single_thread() {
assert_eq!(
optimize_chunk_size_and_thread_limit(50, None, None, Some(1)),
(50, Some(1), 1),
"single threaded - we don't touch that"
);
}
#[test]
fn small_chunk_size_single_thread() {
assert_eq!(
optimize_chunk_size_and_thread_limit(1, None, None, Some(1)),
(1, Some(1), 1),
"single threaded - we don't touch that"
);
}
#[test]
fn small_chunk_size_many_threads() {
assert_eq!(
optimize_chunk_size_and_thread_limit(1, None, None, Some(4)),
(50, Some(4), 4),
"we prefer an arbitrary number, which should really be based on effort, but the caller has to adjust for that"
);
}
}
mod real_values {
use git_features::parallel::optimize_chunk_size_and_thread_limit;
#[test]
fn linux_kernel_pack_my_machine_lookup() {
assert_eq!(
optimize_chunk_size_and_thread_limit(10000, Some(7_500_000), None, Some(4)),
(1000, Some(4), 4),
"the bucket size is capped actually, somewhat arbitrarily"
);
}
#[test]
fn linux_kernel_pack_my_machine_indexed() {
assert_eq!(
optimize_chunk_size_and_thread_limit(1, None, None, Some(4)),
(50, Some(4), 4),
"low values are raised to arbitrary value"
);
assert_eq!(
optimize_chunk_size_and_thread_limit(10000, None, None, Some(4)),
(1000, Some(4), 4),
"high values are capped"
);
}
}
}