Skip to content

Commit 87df90f

Browse files
committed
Adapt aobench for benchmark-interface, add validation and fix encoding
1 parent 543e892 commit 87df90f

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

bench/classic/aobench.rb

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
# coding: US-ASCII
1+
# coding: BINARY
2+
3+
# From https://github.com/ruby/ruby/blob/master/benchmark/app_aobench.rb
4+
# with the encoding comment fixed, with validation and adapted for benchmark-interface
25

36
# AO render benchmark
47
# Original program (C) Syoyo Fujita in Javascript (and other languages)
@@ -11,8 +14,6 @@
1114
NSUBSAMPLES = 2
1215
NAO_SAMPLES = 8
1316

14-
srand(0)
15-
1617
class Vec
1718
def initialize(x, y, z)
1819
@x = x
@@ -174,6 +175,7 @@ def otherBasis(basis, n)
174175

175176
class Scene
176177
def initialize
178+
srand(0)
177179
@spheres = Array.new
178180
@spheres[0] = Sphere.new(Vec.new(-2.0, 0.0, -3.5), 0.5)
179181
@spheres[1] = Sphere.new(Vec.new(-0.5, 0.0, -3.0), 0.5)
@@ -226,7 +228,7 @@ def ambient_occlusion(isect)
226228
Vec.new(occlusion, occlusion, occlusion)
227229
end
228230

229-
def render(w, h, nsubsamples)
231+
def render(w, h, nsubsamples, result)
230232
cnt = 0
231233
nsf = nsubsamples.to_f
232234
h.times do |y|
@@ -269,9 +271,9 @@ def render(w, h, nsubsamples)
269271
r = rad.x / (nsf * nsf)
270272
g = rad.y / (nsf * nsf)
271273
b = rad.z / (nsf * nsf)
272-
printf("%c", clamp(r))
273-
printf("%c", clamp(g))
274-
printf("%c", clamp(b))
274+
result << sprintf("%c", clamp(r))
275+
result << sprintf("%c", clamp(g))
276+
result << sprintf("%c", clamp(b))
275277
end
276278
nil
277279
end
@@ -280,18 +282,14 @@ def render(w, h, nsubsamples)
280282
end
281283
end
282284

283-
alias printf_orig printf
284-
def printf *args
285-
# $fp.printf(*args)
285+
benchmark do
286+
result = "".b
287+
result << "P6\n"
288+
result << sprintf("%d %d\n", IMAGE_WIDTH, IMAGE_HEIGHT)
289+
result << "255\n"
290+
Scene.new.render(IMAGE_WIDTH, IMAGE_HEIGHT, NSUBSAMPLES, result)
291+
# File.write("ao.ppm", result)
292+
result
293+
end.verify do |result|
294+
result.sum == 41835
286295
end
287-
288-
# File.open("ao.ppm", "w") do |fp|
289-
# $fp = fp
290-
printf("P6\n")
291-
printf("%d %d\n", IMAGE_WIDTH, IMAGE_HEIGHT)
292-
printf("255\n")
293-
Scene.new.render(IMAGE_WIDTH, IMAGE_HEIGHT, NSUBSAMPLES)
294-
# end
295-
296-
undef printf
297-
alias printf printf_orig

mx.truffleruby/mx_truffleruby_benchmark.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ def runBenchmark(self, benchmark, bmSuiteArgs):
380380
}]
381381

382382
classic_benchmarks = [
383+
'aobench',
383384
'binary-trees',
384385
'deltablue',
385386
'fannkuch',

0 commit comments

Comments
 (0)