Skip to content

Commit 66f2bd0

Browse files
committed
Add asciidoctor warmup benchmark
1 parent 9e00c2b commit 66f2bd0

File tree

6 files changed

+97
-19
lines changed

6 files changed

+97
-19
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require_relative 'asciidoctor/lib/asciidoctor'
2+
3+
sample_file = File.expand_path('../data/userguide.adoc', __FILE__)
4+
sample_file_text = File.read(sample_file)
5+
document = Asciidoctor.load(sample_file_text)
6+
7+
benchmark 'convert' do
8+
document.convert
9+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require_relative 'asciidoctor/lib/asciidoctor'
2+
3+
sample_file = File.expand_path('../data/userguide.adoc', __FILE__)
4+
sample_file_io = File.open(sample_file)
5+
6+
benchmark 'load-file' do
7+
Asciidoctor.load sample_file_io
8+
sample_file_io.seek 0
9+
end
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
require_relative 'asciidoctor/lib/asciidoctor'
2+
3+
sample_file = File.expand_path('../data/userguide.adoc', __FILE__)
4+
sample_file_text = File.read(sample_file)
5+
6+
benchmark 'load-string' do
7+
Asciidoctor.load sample_file_text
8+
end

bench/asciidoctor/asciidoctor.rb

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,6 @@
2828
end
2929
end
3030

31-
benchmark 'load-string' do
32-
Asciidoctor.load sample_file_text
33-
end
34-
35-
benchmark 'load-file' do
36-
Asciidoctor.load sample_file_io
37-
sample_file_io.seek 0
38-
end
39-
4031
document = Asciidoctor.load(sample_file_text)
4132
converted = document.convert
4233
lines = converted.split('\n')
@@ -81,7 +72,3 @@ def document
8172
benchmark 'join-lines' do
8273
lines * '\n'
8374
end
84-
85-
benchmark 'convert' do
86-
document.convert
87-
end

ci.jsonnet

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ local part_definitions = {
444444
chunky: { benchmarks+:: ["chunky"] },
445445
psd: { benchmarks+:: ["psd"] },
446446
asciidoctor: { benchmarks+:: ["asciidoctor"] },
447+
asciidoctor_warmup: { benchmarks+:: ["asciidoctor-warmup"] },
447448
other_extra: { benchmarks+:: ["savina"] },
448449
other: { benchmarks+:: ["micro", "image-demo", "optcarrot", "synthetic", "rubykon", "liquid"] },
449450

@@ -614,6 +615,17 @@ local composition_environment = utils.add_inclusion_tracking(part_definitions, "
614615
"ruby-benchmarks-asciidoctor-svm-graal-core-multi-tier": shared + asciidoctor + svm_configurations["svm-graal-core"] + $.use.multi_tier,
615616
"ruby-benchmarks-asciidoctor-svm-graal-enterprise": shared + asciidoctor + svm_configurations["svm-graal-enterprise"],
616617
"ruby-benchmarks-asciidoctor-svm-graal-enterprise-multi-tier": shared + asciidoctor + svm_configurations["svm-graal-enterprise"] + $.use.multi_tier,
618+
local asciidoctor_warmup = $.benchmark.runner + $.benchmark.asciidoctor_warmup + { timelimit: "00:55:00" },
619+
"ruby-benchmarks-asciidoctor-mri-warmup": shared + asciidoctor_warmup + other_rubies.mri,
620+
"ruby-benchmarks-asciidoctor-jruby-warmup": shared + asciidoctor_warmup + other_rubies.jruby,
621+
"ruby-benchmarks-asciidoctor-graal-core-warmup": shared + asciidoctor_warmup + graal_configurations["graal-core"],
622+
"ruby-benchmarks-asciidoctor-graal-core-multi-tier-warmup": shared + asciidoctor_warmup + graal_configurations["graal-core"] + $.use.multi_tier,
623+
"ruby-benchmarks-asciidoctor-graal-enterprise-warmup": shared + asciidoctor_warmup + graal_configurations["graal-enterprise"],
624+
"ruby-benchmarks-asciidoctor-graal-enterprise-multi-tier-warmup": shared + asciidoctor_warmup + graal_configurations["graal-enterprise"] + $.use.multi_tier,
625+
"ruby-benchmarks-asciidoctor-svm-graal-core-warmup": shared + asciidoctor_warmup + svm_configurations["svm-graal-core"],
626+
"ruby-benchmarks-asciidoctor-svm-graal-core-multi-tier-warmup": shared + asciidoctor_warmup + svm_configurations["svm-graal-core"] + $.use.multi_tier,
627+
"ruby-benchmarks-asciidoctor-svm-graal-enterprise-warmup": shared + asciidoctor_warmup + svm_configurations["svm-graal-enterprise"],
628+
"ruby-benchmarks-asciidoctor-svm-graal-enterprise-multi-tier-warmup": shared + asciidoctor_warmup + svm_configurations["svm-graal-enterprise"] + $.use.multi_tier,
617629

618630
local other = $.benchmark.runner + $.benchmark.other + $.benchmark.other_extra + { timelimit: "00:40:00" },
619631
local svm_other = $.benchmark.runner + $.benchmark.other + { timelimit: "01:00:00" },

mx.truffleruby/mx_truffleruby_benchmark.py

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,9 @@ def runBenchmark(self, benchmark, bmSuiteArgs):
245245
} for region, region_data in data.items() for n, sample in enumerate(region_data['samples'])]
246246

247247
class AllBenchmarksBenchmarkSuite(RubyBenchmarkSuite):
248+
def config(self):
249+
return {'kind': 'simple'}
250+
248251
def benchmarkList(self, bmSuiteArgs):
249252
raise NotImplementedError()
250253

@@ -270,8 +273,25 @@ def filterLines(self, lines):
270273

271274
def runBenchmark(self, benchmark, bmSuiteArgs):
272275
arguments = ['benchmark']
273-
arguments.extend(['--simple', '--elapsed', '--iterations'])
274-
arguments.extend(['--time', str(self.time())])
276+
if self.config()['kind'] == 'simple':
277+
arguments.extend(['--simple', '--elapsed', '--iterations'])
278+
time = self.time()
279+
if isinstance(time, dict):
280+
if benchmark in time:
281+
time = str(time[benchmark])
282+
else:
283+
time = str(time['default'])
284+
else:
285+
time = str(self.time())
286+
arguments.extend(['--time', time])
287+
elif self.config()['kind'] == 'fixed-iterations':
288+
iterations_arg = ','.join([str(i) for i in sorted(self.config()['iterations'][benchmark].keys())])
289+
arguments.extend(['--elapsed', '--iterations', '--ips'])
290+
arguments.extend(['--fixed-iterations'])
291+
arguments.extend([iterations_arg])
292+
else:
293+
raise AssertionError("Unknown benchmark kind: " + self.config()['kind'])
294+
275295
if ':' in benchmark:
276296
benchmark_file, benchmark_name = benchmark.split(':')
277297
benchmark_names = [benchmark_name]
@@ -287,6 +307,7 @@ def runBenchmark(self, benchmark, bmSuiteArgs):
287307
lines = out.data.split('\n')[1:-1]
288308

289309
data = self.filterLines(lines)
310+
iterations = [d for n, d in enumerate(data) if n % 3 == 0]
290311
elapsed = [d for n, d in enumerate(data) if n % 3 == 1]
291312
samples = [d for n, d in enumerate(data) if n % 3 == 2]
292313

@@ -311,6 +332,15 @@ def runBenchmark(self, benchmark, bmSuiteArgs):
311332
'extra.metric.elapsed-num': elapsed[-1] + 2.0 if elapsed else 2.0, # just put the data point beyond the last one a bit
312333
'error': 'optimised away'
313334
}]
335+
elif self.config()['kind'] == 'fixed-iterations':
336+
iteration_config = self.config()['iterations'][benchmark]
337+
return [{
338+
'benchmark': benchmark,
339+
'metric.name': iteration_config[iteration],
340+
'metric.value': e,
341+
'metric.unit': 's',
342+
'metric.better': 'lower'
343+
} for n, (e, iteration) in enumerate(zip(elapsed, iterations)) if iteration in iteration_config]
314344
else:
315345
return [{
316346
'benchmark': benchmark,
@@ -469,15 +499,15 @@ def time(self):
469499
'asciidoctor:string-lines',
470500
'asciidoctor:read-line',
471501
'asciidoctor:restore-line',
472-
'asciidoctor:load-string',
473-
'asciidoctor:load-file',
474502
'asciidoctor:quote-match',
475503
'asciidoctor:quote-sub',
476504
'asciidoctor:join-lines',
477-
'asciidoctor:convert'
505+
'asciidoctor-convert',
506+
'asciidoctor-load-file',
507+
'asciidoctor-load-string'
478508
]
479509

480-
asciidoctor_benchmark_time = 120
510+
asciidoctor_benchmark_time = {'asciidoctor-convert':400, 'asciidoctor-load-file':400, 'asciidoctor-load-string':400, 'default': 120}
481511

482512
class AsciidoctorBenchmarkSuite(AllBenchmarksBenchmarkSuite):
483513
def name(self):
@@ -642,6 +672,28 @@ def benchmarkList(self, bmSuiteArgs):
642672
def time(self):
643673
return 60
644674

675+
asciidoctor_warmup_benchmarks = [
676+
'asciidoctor-convert',
677+
'asciidoctor-load-file',
678+
'asciidoctor-load-string'
679+
]
680+
681+
class AsciidoctorWarmupBenchmarkSuite(AllBenchmarksBenchmarkSuite):
682+
def config(self):
683+
iterations = {'asciidoctor-convert': {10:'startup', 20:'early-warmup', 100:'late-warmup'},
684+
'asciidoctor-load-file': {10:'startup', 100:'early-warmup', 500:'late-warmup'},
685+
'asciidoctor-load-string': {10:'startup', 100:'early-warmup', 500:'late-warmup'}}
686+
return {'kind': 'fixed-iterations', 'iterations': iterations}
687+
688+
def name(self):
689+
return 'asciidoctor-warmup'
690+
691+
def directory(self):
692+
return 'asciidoctor'
693+
694+
def benchmarkList(self, bmSuiteArgs):
695+
return asciidoctor_warmup_benchmarks
696+
645697
mx_benchmark.add_bm_suite(BuildStatsBenchmarkSuite())
646698
mx_benchmark.add_bm_suite(AllocationBenchmarkSuite())
647699
mx_benchmark.add_bm_suite(InstructionsBenchmarkSuite())
@@ -660,3 +712,4 @@ def time(self):
660712
mx_benchmark.add_bm_suite(ServerBenchmarkSuite())
661713
mx_benchmark.add_bm_suite(RubykonBenchmarkSuite())
662714
mx_benchmark.add_bm_suite(LiquidBenchmarkSuite())
715+
mx_benchmark.add_bm_suite(AsciidoctorWarmupBenchmarkSuite())

0 commit comments

Comments
 (0)