-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ff8207
commit c73e5e6
Showing
3 changed files
with
73 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import 'dart:math'; | ||
|
||
import 'package:benchmark_harness/benchmark_harness.dart'; | ||
import 'package:ordered_set/ordered_set.dart'; | ||
|
||
import '../test/comparable_object.dart'; | ||
|
||
class IterationBenchmark extends BenchmarkBase { | ||
late final OrderedSet<ComparableObject> set; | ||
|
||
IterationBenchmark() : super('Iteration Benchmark'); | ||
|
||
static void main() { | ||
IterationBenchmark().report(); | ||
} | ||
|
||
@override | ||
void setup() { | ||
set = OrderedSet(); | ||
for (var i = 0; i < 1000; i++) { | ||
final l = (10 + sqrt(i)).floor(); | ||
for (var j = 0; j <= l; j++) { | ||
set.add(ComparableObject(i, '$i-$j')); | ||
} | ||
} | ||
} | ||
|
||
@override | ||
void exercise() { | ||
for (final element in set) { | ||
_consume(element); | ||
} | ||
} | ||
|
||
void _consume(ComparableObject obj) { | ||
// NO-OP | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,7 @@ | ||
import 'dart:math'; | ||
|
||
import 'package:benchmark_harness/benchmark_harness.dart'; | ||
import 'package:ordered_set/ordered_set.dart'; | ||
|
||
import '../test/comparable_object.dart'; | ||
|
||
class IterationBenchmark extends BenchmarkBase { | ||
late final OrderedSet<ComparableObject> set; | ||
|
||
IterationBenchmark() : super('Template'); | ||
|
||
static void main() { | ||
IterationBenchmark().report(); | ||
} | ||
|
||
@override | ||
void setup() { | ||
set = OrderedSet(); | ||
for (var i = 0; i < 1000; i++) { | ||
final l = (10 + sqrt(i)).floor(); | ||
for (var j = 0; j <= l; j++) { | ||
set.add(ComparableObject(i, '$i-$j')); | ||
} | ||
} | ||
} | ||
|
||
@override | ||
void exercise() { | ||
for (final element in set) { | ||
_consume(element); | ||
} | ||
} | ||
|
||
void _consume(ComparableObject obj) { | ||
// NO-OP | ||
} | ||
} | ||
import 'iteration_benchmark.dart'; | ||
import 'other_benchmark.dart'; | ||
|
||
void main() { | ||
IterationBenchmark.main(); | ||
OtherBenchmark.main(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import 'package:benchmark_harness/benchmark_harness.dart'; | ||
import 'package:ordered_set/ordered_set.dart'; | ||
|
||
class OtherBenchmark extends BenchmarkBase { | ||
final OrderedSet<int> set = OrderedSet(); | ||
|
||
OtherBenchmark() : super('Other Benchmark'); | ||
|
||
static void main() { | ||
OtherBenchmark().report(); | ||
} | ||
|
||
@override | ||
void setup() { | ||
for (var i = 0; i < 1000; i++) { | ||
for (var j = 0; j <= i; j++) { | ||
set.add(i); | ||
} | ||
} | ||
} | ||
|
||
@override | ||
void exercise() { | ||
for (final element in set) { | ||
_consume(element); | ||
} | ||
} | ||
|
||
void _consume(int obj) { | ||
// NO-OP | ||
} | ||
} |