-
Notifications
You must be signed in to change notification settings - Fork 198
Expand file tree
/
Copy pathset_strings.dart
More file actions
105 lines (88 loc) · 2.67 KB
/
Copy pathset_strings.dart
File metadata and controls
105 lines (88 loc) · 2.67 KB
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
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import '../benchmark.dart';
import '../generated/benchmark.pb.dart'
show BenchmarkID, Params, Request, Sample;
import '../generated/string_grid.pb.dart' as pb;
/// A benchmark that sets each value in a grid of string fields.
class SetStringsBenchmark extends Benchmark {
static const width = 10;
final int height;
final String? fillValue;
late pb.Grid10 grid;
SetStringsBenchmark(this.height, this.fillValue) : super($id);
@override
String get summary {
var fill = fillValue == null ? 'null' : "'$fillValue'";
return '${id.name}($height x $fill)';
}
@override
Params makeParams() {
var p = Params()..messageCount = height;
if (fillValue != null) p.stringValue = fillValue!;
return p;
}
@override
void setup() {
grid = _makeGrid(width, height, fillValue);
}
// makes a rectangle where no fields have been set.
static pb.Grid10 _makeGrid(int width, int height, String? fillValue) {
var grid = pb.Grid10();
for (var y = 0; y < height; y++) {
var line = pb.Line10();
if (fillValue != null) {
for (var x = 0; x < width; x++) {
var tag = getTagForColumn(line, x);
line.setField(tag, fillValue);
}
}
grid.lines.add(line);
}
return grid;
}
static int getTagForColumn(pb.Line10 line, int x) {
return line.getTagNumber('cell${x + 1}')!; // assume x start from 1
}
@override
int exercise() {
const reps = 100;
for (var i = 0; i < reps; i++) {
run();
}
return reps;
}
@override
void run() {
var newValue = '';
for (var line in grid.lines) {
line.cell1 = newValue;
line.cell2 = newValue;
line.cell3 = newValue;
line.cell4 = newValue;
line.cell5 = newValue;
line.cell6 = newValue;
line.cell7 = newValue;
line.cell8 = newValue;
line.cell9 = newValue;
line.cell10 = newValue;
}
}
@override
void setCounts(Sample m) {
m.counts.stringWrites = width * height * m.loopCount;
}
@override
double measureSample(Sample? s) => stringWritesPerMillisecond(s);
@override
String get measureSampleUnits => 'string writes/ms';
static const $id = BenchmarkID.SET_STRINGS;
static final $type = BenchmarkType($id, $create);
static SetStringsBenchmark $create(Request r) {
assert(r.params.hasMessageCount());
String? value;
if (r.params.hasStringValue()) value = r.params.stringValue;
return SetStringsBenchmark(r.params.messageCount, value);
}
}