Skip to content

Commit c3fb291

Browse files
committed
bench: take drop time into account to avoid werid results
1 parent ceb5e90 commit c3fb291

File tree

2 files changed

+38
-50
lines changed

2 files changed

+38
-50
lines changed

README.md

+18-18
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,24 @@ The following benchmarks were conducted using a real-world editing history from
77
latch.bio, comprising 1,659,541 operations. All benchmarks results below were
88
performed on a MacBook Pro M1 2020.
99

10-
| name | task | time |
11-
| -------------------------------- | ------------------------------- | ------------------------ |
12-
| 0 Old Snapshot Format on 0.16.12 | Import | 15.785373ms +- 19.596µs |
13-
| | Import+GetAllValues | 15.848977ms +- 26.184µs |
14-
| | Import+GetAllValues+Edit | 16.352828ms +- 119.143µs |
15-
| | Import+GetAllValues+Edit+Expo | 30.745277ms +- 58.265µs |
16-
| 1 Old Snapshot Format on 1.0.0 | Import | 16.358149ms +- 27.291µs |
17-
| | Import+GetAllValues | 16.185157ms +- 26.305µs |
18-
| | Import+GetAllValues+Edit | 16.293045ms +- 21.654µs |
19-
| | Import+GetAllValues+Edit+Export | 31.146791ms +- 66.619µs |
20-
| 2 New Snapshot Format | Import | 1.125041ms +- 11.812µs |
21-
| | Import+GetAllValues | 1.120306ms +- 12.544µs |
22-
| | Import+GetAllValues+Edit | 1.186773ms +- 49.587µs |
23-
| | Import+GetAllValues+Edit+Export | 5.44709ms +- 77.165µs |
24-
| 3 Shallow Snapshot Format | Import | 347.397µs +- 2.189µs |
25-
| | Import+GetAllValues | 371.521µs +- 2.893µs |
26-
| | Import+GetAllValues+Edit | 202.047µs +- 10.058µs |
27-
| | Import+GetAllValues+Edit+Export | 818.688µs +- 2.395µs |
10+
| name | task | time |
11+
| -------------------------------- | ------------------------------- | ----------------------- |
12+
| 0 Old Snapshot Format on 0.16.12 | Import | 17.339081ms +- 29.8µs |
13+
| | Import+GetAllValues | 17.395361ms +- 43.714µs |
14+
| | Import+GetAllValues+Edit | 17.463965ms +- 26.334µs |
15+
| | Import+GetAllValues+Edit+Expo | 32.388292ms +- 56.006µs |
16+
| 1 Old Snapshot Format on 1.0.0 | Import | 16.882856ms +- 34.296µs |
17+
| | Import+GetAllValues | 16.820565ms +- 30.189µs |
18+
| | Import+GetAllValues+Edit | 16.934977ms +- 36.064µs |
19+
| | Import+GetAllValues+Edit+Export | 31.161731ms +- 80.663µs |
20+
| 2 New Snapshot Format | Import | 1.150184ms +- 10.06µs |
21+
| | Import+GetAllValues | 1.192459ms +- 12.164µs |
22+
| | Import+GetAllValues+Edit | 1.208262ms +- 12.034µs |
23+
| | Import+GetAllValues+Edit+Export | 5.46355ms +- 77.198µs |
24+
| 3 Shallow Snapshot Format | Import | 374.98µs +- 8.472µs |
25+
| | Import+GetAllValues | 375.227µs +- 1.596µs |
26+
| | Import+GetAllValues+Edit | 374.859µs +- 1.398µs |
27+
| | Import+GetAllValues+Edit+Export | 843.65µs +- 5.116µs |
2828

2929
```log
3030

benches/loro_benchmarks.rs

+20-32
Original file line numberDiff line numberDiff line change
@@ -51,39 +51,34 @@ fn bench_version<F>(
5151
{
5252
group.bench_function(format!("{} - Import", name), |b| {
5353
b.iter_custom(|iters| {
54-
let mut total = std::time::Duration::ZERO;
54+
let start = Instant::now();
5555
for _ in 0..iters {
56-
let start = Instant::now();
5756
let doc = LoroDoc::new();
5857
doc.import(black_box(input)).unwrap();
59-
total += start.elapsed();
6058
black_box(doc);
6159
}
62-
total
60+
start.elapsed()
6361
});
6462
});
6563

6664
group.bench_function(format!("{} - Import+GetAllValues", name), |b| {
6765
b.iter_custom(|iters| {
68-
let mut total = std::time::Duration::ZERO;
66+
let start = Instant::now();
6967
for _ in 0..iters {
70-
let start = Instant::now();
7168
let doc = LoroDoc::new();
7269
doc.import(black_box(input)).unwrap();
7370
let value = doc.get_deep_value();
74-
total += start.elapsed();
7571
black_box(doc);
7672
black_box(value);
7773
}
78-
total
74+
start.elapsed()
7975
});
8076
});
8177

8278
group.bench_function(format!("{} - Import+GetAllValues+Edit", name), |b| {
8379
b.iter_custom(|iters| {
84-
let mut total = std::time::Duration::ZERO;
80+
let start = Instant::now();
8581
for _ in 0..iters {
86-
let start = Instant::now();
8782
let doc = LoroDoc::new();
8883
doc.import(black_box(input)).unwrap();
8984
let value = doc.get_deep_value();
@@ -93,19 +88,18 @@ fn bench_version<F>(
9388
let text = cell.insert_container("source", LoroText::new()).unwrap();
9489
text.insert(0, "Hello world!").unwrap();
9590
doc.commit();
96-
total += start.elapsed();
9791
black_box(doc);
9892
black_box(value);
93+
black_box(text);
9994
}
100-
total
95+
start.elapsed()
10196
});
10297
});
10398

10499
group.bench_function(format!("{} - Import+GetAllValues+Edit+Export", name), |b| {
105100
b.iter_custom(|iters| {
106-
let mut total = std::time::Duration::ZERO;
101+
let start = Instant::now();
107102
for _ in 0..iters {
108-
let start = Instant::now();
109103
let doc = LoroDoc::new();
110104
doc.import(black_box(input)).unwrap();
111105
let value = doc.get_deep_value();
@@ -117,11 +111,11 @@ fn bench_version<F>(
117111
doc.commit();
118112
let snapshot = export_fn(&doc);
119113
black_box(snapshot);
120-
total += start.elapsed();
121114
black_box(doc);
122115
black_box(value);
116+
black_box(text);
123117
}
124-
total
118+
start.elapsed()
125119
});
126120
});
127121
}
@@ -136,39 +130,34 @@ fn bench_version_016<F>(
136130
{
137131
group.bench_function(format!("{} - Import", name), |b| {
138132
b.iter_custom(|iters| {
139-
let mut total = std::time::Duration::ZERO;
133+
let start = Instant::now();
140134
for _ in 0..iters {
141-
let start = Instant::now();
142135
let doc = loro_016::LoroDoc::new();
143136
doc.import(black_box(input)).unwrap();
144-
total += start.elapsed();
145137
black_box(doc);
146138
}
147-
total
139+
start.elapsed()
148140
});
149141
});
150142

151143
group.bench_function(format!("{} - Import+GetAllValues", name), |b| {
152144
b.iter_custom(|iters| {
153-
let mut total = std::time::Duration::ZERO;
145+
let start = Instant::now();
154146
for _ in 0..iters {
155-
let start = Instant::now();
156147
let doc = loro_016::LoroDoc::new();
157148
doc.import(black_box(input)).unwrap();
158149
let value = doc.get_deep_value();
159-
total += start.elapsed();
160150
black_box(doc);
161151
black_box(value);
162152
}
163-
total
153+
start.elapsed()
164154
});
165155
});
166156

167157
group.bench_function(format!("{} - Import+GetAllValues+Edit", name), |b| {
168158
b.iter_custom(|iters| {
169-
let mut total = std::time::Duration::ZERO;
159+
let start = Instant::now();
170160
for _ in 0..iters {
171-
let start = Instant::now();
172161
let doc = loro_016::LoroDoc::new();
173162
doc.import(black_box(input)).unwrap();
174163
let value = doc.get_deep_value();
@@ -180,19 +169,18 @@ fn bench_version_016<F>(
180169
.unwrap();
181170
text.insert(0, "Hello world!").unwrap();
182171
doc.commit();
183-
total += start.elapsed();
184172
black_box(doc);
185173
black_box(value);
174+
black_box(text);
186175
}
187-
total
176+
start.elapsed()
188177
});
189178
});
190179

191180
group.bench_function(format!("{} - Import+GetAllValues+Edit+Export", name), |b| {
192181
b.iter_custom(|iters| {
193-
let mut total = std::time::Duration::ZERO;
182+
let start = Instant::now();
194183
for _ in 0..iters {
195-
let start = Instant::now();
196184
let doc = loro_016::LoroDoc::new();
197185
doc.import(black_box(input)).unwrap();
198186
let value = doc.get_deep_value();
@@ -206,11 +194,11 @@ fn bench_version_016<F>(
206194
doc.commit();
207195
let snapshot = export_fn(&doc);
208196
black_box(snapshot);
209-
total += start.elapsed();
210197
black_box(doc);
211198
black_box(value);
199+
black_box(text);
212200
}
213-
total
201+
start.elapsed()
214202
});
215203
});
216204
}

0 commit comments

Comments
 (0)