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
2
5
3
6
# AO render benchmark
4
7
# Original program (C) Syoyo Fujita in Javascript (and other languages)
11
14
NSUBSAMPLES = 2
12
15
NAO_SAMPLES = 8
13
16
14
- srand ( 0 )
15
-
16
17
class Vec
17
18
def initialize ( x , y , z )
18
19
@x = x
@@ -174,6 +175,7 @@ def otherBasis(basis, n)
174
175
175
176
class Scene
176
177
def initialize
178
+ srand ( 0 )
177
179
@spheres = Array . new
178
180
@spheres [ 0 ] = Sphere . new ( Vec . new ( -2.0 , 0.0 , -3.5 ) , 0.5 )
179
181
@spheres [ 1 ] = Sphere . new ( Vec . new ( -0.5 , 0.0 , -3.0 ) , 0.5 )
@@ -226,7 +228,7 @@ def ambient_occlusion(isect)
226
228
Vec . new ( occlusion , occlusion , occlusion )
227
229
end
228
230
229
- def render ( w , h , nsubsamples )
231
+ def render ( w , h , nsubsamples , result )
230
232
cnt = 0
231
233
nsf = nsubsamples . to_f
232
234
h . times do |y |
@@ -269,9 +271,9 @@ def render(w, h, nsubsamples)
269
271
r = rad . x / ( nsf * nsf )
270
272
g = rad . y / ( nsf * nsf )
271
273
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 ) )
275
277
end
276
278
nil
277
279
end
@@ -280,18 +282,14 @@ def render(w, h, nsubsamples)
280
282
end
281
283
end
282
284
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
286
295
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
0 commit comments