Skip to content

Commit ff47099

Browse files
committed
[GR-26172] Add asciidoctor warmup benchmark
PullRequest: truffleruby/2030
2 parents 57811f5 + 7ad1034 commit ff47099

File tree

6 files changed

+117
-22
lines changed

6 files changed

+117
-22
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
@@ -440,6 +440,7 @@ local part_definitions = {
440440
asciidoctor: { benchmarks+:: ["asciidoctor"] },
441441
other_extra: { benchmarks+:: ["savina"] },
442442
other: { benchmarks+:: ["micro", "image-demo", "optcarrot", "synthetic", "rubykon", "liquid"] },
443+
warmup: { benchmarks+:: ["ruby-warmup"] },
443444

444445
server: {
445446
local build = self,
@@ -608,6 +609,17 @@ local composition_environment = utils.add_inclusion_tracking(part_definitions, "
608609
"ruby-benchmarks-asciidoctor-svm-graal-core-multi-tier": shared + asciidoctor + svm_configurations["svm-graal-core"] + $.use.multi_tier,
609610
"ruby-benchmarks-asciidoctor-svm-graal-enterprise": shared + asciidoctor + svm_configurations["svm-graal-enterprise"],
610611
"ruby-benchmarks-asciidoctor-svm-graal-enterprise-multi-tier": shared + asciidoctor + svm_configurations["svm-graal-enterprise"] + $.use.multi_tier,
612+
local warmup = $.benchmark.runner + $.benchmark.warmup + { timelimit: "00:55:00" },
613+
"ruby-benchmarks-warmup-mri": shared + warmup + other_rubies.mri,
614+
"ruby-benchmarks-warmup-jruby": shared + warmup + other_rubies.jruby,
615+
"ruby-benchmarks-warmup-graal-core": shared + warmup + graal_configurations["graal-core"],
616+
"ruby-benchmarks-warmup-graal-core-multi-tier": shared + warmup + graal_configurations["graal-core"] + $.use.multi_tier,
617+
"ruby-benchmarks-warmup-graal-enterprise": shared + warmup + graal_configurations["graal-enterprise"],
618+
"ruby-benchmarks-warmup-graal-enterprise-multi-tier": shared + warmup + graal_configurations["graal-enterprise"] + $.use.multi_tier,
619+
"ruby-benchmarks-warmup-svm-graal-core": shared + warmup + svm_configurations["svm-graal-core"],
620+
"ruby-benchmarks-warmup-svm-graal-core-multi-tier": shared + warmup + svm_configurations["svm-graal-core"] + $.use.multi_tier,
621+
"ruby-benchmarks-warmup-svm-graal-enterprise": shared + warmup + svm_configurations["svm-graal-enterprise"],
622+
"ruby-benchmarks-warmup-svm-graal-enterprise-multi-tier": shared + warmup + svm_configurations["svm-graal-enterprise"] + $.use.multi_tier,
611623

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

mx.truffleruby/mx_truffleruby_benchmark.py

Lines changed: 79 additions & 9 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

@@ -261,24 +264,48 @@ def filterLines(self, lines):
261264
data = []
262265
for line in lines:
263266
try:
264-
data.append(float(line))
267+
data.append(int(line))
265268
except ValueError:
266-
mx.log_error(line)
269+
try:
270+
data.append(float(line))
271+
except ValueError:
272+
mx.log_error(line)
267273
if len(data) % 3 != 0:
268274
raise AssertionError("Number of values not a multiple of 3")
269275
return data
270276

271277
def runBenchmark(self, benchmark, bmSuiteArgs):
278+
directory = self.directory()
279+
if directory is None:
280+
directory, benchmark = benchmark.split('/')
281+
272282
arguments = ['benchmark']
273-
arguments.extend(['--simple', '--elapsed', '--iterations'])
274-
arguments.extend(['--time', str(self.time())])
283+
if self.config()['kind'] == 'simple':
284+
arguments.extend(['--simple', '--elapsed', '--iterations'])
285+
time = self.time()
286+
if isinstance(time, dict):
287+
if benchmark in time:
288+
time = str(time[benchmark])
289+
else:
290+
time = str(time['default'])
291+
else:
292+
time = str(self.time())
293+
arguments.extend(['--time', time])
294+
elif self.config()['kind'] == 'fixed-iterations':
295+
iterations_arg = ','.join([str(i) for i in sorted(self.config()['iterations'][benchmark].keys())])
296+
arguments.extend(['--elapsed', '--iterations', '--ips'])
297+
arguments.extend(['--fixed-iterations'])
298+
arguments.extend([iterations_arg])
299+
else:
300+
raise AssertionError("Unknown benchmark kind: " + self.config()['kind'])
301+
275302
if ':' in benchmark:
276303
benchmark_file, benchmark_name = benchmark.split(':')
277304
benchmark_names = [benchmark_name]
278305
else:
279306
benchmark_file = benchmark
280307
benchmark_names = []
281-
arguments.extend(['bench/' + self.directory() + '/' + benchmark_file + '.rb'])
308+
arguments.extend(['bench/' + directory + '/' + benchmark_file + '.rb'])
282309
arguments.extend(benchmark_names)
283310
arguments.extend(bmSuiteArgs)
284311
out = mx.OutputCapture()
@@ -287,6 +314,7 @@ def runBenchmark(self, benchmark, bmSuiteArgs):
287314
lines = out.data.split('\n')[1:-1]
288315

289316
data = self.filterLines(lines)
317+
iterations = [d for n, d in enumerate(data) if n % 3 == 0]
290318
elapsed = [d for n, d in enumerate(data) if n % 3 == 1]
291319
samples = [d for n, d in enumerate(data) if n % 3 == 2]
292320

@@ -311,6 +339,16 @@ def runBenchmark(self, benchmark, bmSuiteArgs):
311339
'extra.metric.elapsed-num': elapsed[-1] + 2.0 if elapsed else 2.0, # just put the data point beyond the last one a bit
312340
'error': 'optimised away'
313341
}]
342+
elif self.config()['kind'] == 'fixed-iterations':
343+
iteration_config = self.config()['iterations'][benchmark]
344+
return [{
345+
'benchmark': benchmark,
346+
'metric.name': iteration_config[iteration],
347+
'metric.iteration': iteration,
348+
'metric.value': e,
349+
'metric.unit': 's',
350+
'metric.better': 'lower'
351+
} for n, (e, iteration) in enumerate(zip(elapsed, iterations)) if iteration in iteration_config]
314352
else:
315353
return [{
316354
'benchmark': benchmark,
@@ -469,15 +507,20 @@ def time(self):
469507
'asciidoctor:string-lines',
470508
'asciidoctor:read-line',
471509
'asciidoctor:restore-line',
472-
'asciidoctor:load-string',
473-
'asciidoctor:load-file',
474510
'asciidoctor:quote-match',
475511
'asciidoctor:quote-sub',
476512
'asciidoctor:join-lines',
477-
'asciidoctor:convert'
513+
'asciidoctor-convert',
514+
'asciidoctor-load-file',
515+
'asciidoctor-load-string'
478516
]
479517

480-
asciidoctor_benchmark_time = 120
518+
asciidoctor_benchmark_time = {
519+
'asciidoctor-convert': 400,
520+
'asciidoctor-load-file': 400,
521+
'asciidoctor-load-string': 400,
522+
'default': 120
523+
}
481524

482525
class AsciidoctorBenchmarkSuite(AllBenchmarksBenchmarkSuite):
483526
def name(self):
@@ -642,6 +685,32 @@ def benchmarkList(self, bmSuiteArgs):
642685
def time(self):
643686
return 60
644687

688+
warmup_benchmarks = [
689+
'asciidoctor/asciidoctor-convert',
690+
'asciidoctor/asciidoctor-load-file',
691+
'asciidoctor/asciidoctor-load-string',
692+
'rubykon/rubykon',
693+
]
694+
695+
class WarmupBenchmarkSuite(AllBenchmarksBenchmarkSuite):
696+
def config(self):
697+
iterations = {
698+
'asciidoctor-convert': {10:'startup', 100:'early-warmup', 500:'late-warmup'},
699+
'asciidoctor-load-file': {10:'startup', 100:'early-warmup', 500:'late-warmup'},
700+
'asciidoctor-load-string': {10:'startup', 100:'early-warmup', 500:'late-warmup'},
701+
'rubykon': {1:'startup', 10:'early-warmup', 30:'late-warmup'},
702+
}
703+
return {'kind': 'fixed-iterations', 'iterations': iterations}
704+
705+
def name(self):
706+
return 'ruby-warmup'
707+
708+
def directory(self):
709+
return None
710+
711+
def benchmarkList(self, bmSuiteArgs):
712+
return warmup_benchmarks
713+
645714
mx_benchmark.add_bm_suite(BuildStatsBenchmarkSuite())
646715
mx_benchmark.add_bm_suite(AllocationBenchmarkSuite())
647716
mx_benchmark.add_bm_suite(InstructionsBenchmarkSuite())
@@ -660,3 +729,4 @@ def time(self):
660729
mx_benchmark.add_bm_suite(ServerBenchmarkSuite())
661730
mx_benchmark.add_bm_suite(RubykonBenchmarkSuite())
662731
mx_benchmark.add_bm_suite(LiquidBenchmarkSuite())
732+
mx_benchmark.add_bm_suite(WarmupBenchmarkSuite())

0 commit comments

Comments
 (0)