Skip to content

Commit 8346d42

Browse files
committed
Move Some Tests Around
1 parent 9a97299 commit 8346d42

File tree

7 files changed

+93
-8
lines changed

7 files changed

+93
-8
lines changed

test/all_tests.dart

Lines changed: 0 additions & 4 deletions
This file was deleted.

test/benchmarks/config.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
part of github.benchmark;
2+
3+
final RepositorySlug REPOSITORY_SLUG = new RepositorySlug("DirectMyFile", "github.dart");
4+
5+
final String TOKEN = "5fdec2b77527eae85f188b7b2bfeeda170f26883";

test/benchmarks/harness.dart

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
part of github.benchmark;
2+
3+
typedef Future<Stopwatch> Benchmark();
4+
5+
class BenchmarkHelper {
6+
static void prettyPrint(Map<String, List<Stopwatch>> results) {
7+
print("Results:");
8+
results.forEach((name, result) {
9+
var total = result.map((it) => it.elapsedMilliseconds).reduce((a, b) => a + b);
10+
var avg = total / result.length as num;
11+
print(" - ${name}:");
12+
print(" - Average: ${avg}ms");
13+
print(" - Times:");
14+
for (var resultz in result) {
15+
print(" - ${resultz.elapsedMilliseconds}ms");
16+
}
17+
});
18+
}
19+
}
20+
21+
Future<List<Stopwatch>> runBenchmark(int times, Benchmark benchmark) {
22+
var group = new FutureGroup();
23+
for (var i = 0; i < times; i++) {
24+
group.add(benchmark());
25+
}
26+
return group.future;
27+
}
28+
29+
Future<Map<String, List<Stopwatch>>> runBenchmarks(int times, Map<String, Benchmark> benchmarks) {
30+
var group = new FutureGroup();
31+
var results = {};
32+
benchmarks.forEach((String name, Benchmark benchmark) {
33+
results[name] = [];
34+
for (var i = 0; i < times; i++) {
35+
group.add(benchmark().then((watch) {
36+
results[name].add(watch);
37+
}));
38+
}
39+
});
40+
41+
return group.future.then((_) {
42+
return results;
43+
});
44+
}

test/benchmarks/main.dart

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
library github.benchmark;
2+
3+
import "dart:async";
4+
import "dart:io";
5+
6+
import "package:github/server.dart";
7+
8+
import "package:quiver/async.dart";
9+
10+
part 'repository.dart';
11+
part 'harness.dart';
12+
part 'config.dart';
13+
14+
GitHub github;
15+
16+
void main() {
17+
int times = 10;
18+
github = createGitHubClient(auth: new Authentication.withToken(TOKEN));
19+
runBenchmarks(times, {
20+
"Fetch Repository": fetchRepository,
21+
"Fetch Commits": fetchCommits
22+
}).then((results) {
23+
BenchmarkHelper.prettyPrint(results);
24+
exit(0);
25+
});
26+
}

test/benchmarks/repository.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
part of github.benchmark;
2+
3+
Future<Stopwatch> fetchRepository() {
4+
var watch = new Stopwatch()..start();
5+
return github.repository(REPOSITORY_SLUG).then((repo) {
6+
watch.stop();
7+
return watch;
8+
});
9+
}
10+
11+
Future<Stopwatch> fetchCommits() {
12+
var watch = new Stopwatch()..start();
13+
14+
return github.commits(REPOSITORY_SLUG).toList().then((commits) {
15+
watch.stop();
16+
return watch;
17+
});
18+
}
File renamed without changes.

test/vm_tests.dart

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy