|
33 | 33 |
|
34 | 34 | @testset "RayTracingWeekend.jl" begin
|
35 | 35 | t_col = SA[0.4, 0.5, 0.1] # test color
|
| 36 | + |
| 37 | + # Verify that no heap allocations occur for low-level functions |
36 | 38 | @test (@ballocated squared_length($t_col)) == 0 # 1.162 ns
|
37 | 39 |
|
38 | 40 | @test !near_zero(t_col)
|
39 | 41 | @test (@ballocated near_zero($t_col)) == 0 # 1.382 ns
|
40 | 42 |
|
| 43 | + #@show @btime rgb($t_col) # 1.382 ns |
| 44 | + @test (@ballocated rgb($t_col)) == 0 |
41 | 45 |
|
42 |
| - @show rgb(t_col) |
43 |
| - # #rgb($t_col) # 1.172 ns (0 allocations: 0 bytes) |
44 |
| - |
45 |
| - # #rgb_gamma2($t_col) # 3.927 ns (0 allocations: 0 bytes) |
46 |
| - |
47 |
| - # _origin = SA[0.0,0.0,0.0] |
48 |
| - # _v3_minusY = SA[0.0,-1.0,0.0] |
49 |
| - # _t_ray1 = Ray(_origin, _v3_minusY) |
50 |
| - # # Float32: 6.161 ns (0 allocations: 0 bytes) |
51 |
| - # # Float64: 6.900 ns (0 allocations: 0 bytes) |
52 |
| - # #@btime Ray($_origin, $_v3_minusY) |
53 |
| - |
54 |
| - # #@btime point($_t_ray1, 0.5) # 1.412 ns (0 allocations: 0 bytes) |
55 |
| - |
56 |
| - # # 1.402 ns (0 allocations: 0 bytes) |
57 |
| - # #@btime skycolor($_t_ray1) |
58 |
| - |
59 |
| - # # 1.412 ns (0 allocations: 0 bytes) |
60 |
| - # #@btime rgb(skycolor($_t_ray1)) # 291.492 ns (4 allocations: 80 bytes) |
61 |
| - |
62 |
| - # #@btime trand() |
63 |
| - |
64 |
| - # # 2.695 ns (0 allocations: 0 bytes) |
65 |
| - # #@btime random_between(50.0, 100.0) |
| 46 | + _origin = SA[0.0,0.0,0.0] |
| 47 | + _v3_minusY = SA[0.0,-1.0,0.0] |
| 48 | + _t_ray1 = Ray(_origin, _v3_minusY) |
| 49 | + |
| 50 | + # Float32: 6.161 ns (0 allocations: 0 bytes) |
| 51 | + # Float64: 6.900 ns (0 allocations: 0 bytes) |
| 52 | + @test (@ballocated Ray($_origin, $_v3_minusY)) == 0 |
| 53 | + |
| 54 | + @test (@ballocated point($_t_ray1, 0.5)) == 0 # 1.412 ns |
66 | 55 |
|
67 |
| - # #@btime random_vec3(-1.0,1.0) |
| 56 | + @test (@ballocated skycolor($_t_ray1)) == 0 # 1.402 ns |
68 | 57 |
|
69 |
| - # #@btime random_vec2(-1.0f0,1.0f0) # 3.677 ns (0 allocations: 0 bytes) |
| 58 | + @test (@ballocated rgb(skycolor($_t_ray1))) == 0 # 1.412 ns |
| 59 | + |
| 60 | + @test (@ballocated trand()) == 0 |
| 61 | + |
| 62 | + @test (@ballocated random_between(50.0, 100.0)) == 0 # 2.695 ns |
70 | 63 |
|
| 64 | + @test (@ballocated random_vec3(-1.0,1.0)) == 0 |
| 65 | + |
| 66 | + @test (@ballocated random_vec2(-1.0f0,1.0f0)) == 0 |
| 67 | + |
71 | 68 | # # REMEMBER: the times are somewhat random! Use best timing of 5!
|
72 |
| - # # Float32: 34.690 ns (0 allocations: 0 bytes) |
73 |
| - # # Float64: 34.065 ns (0 allocations: 0 bytes) |
74 |
| - # # rand() using MersenneTwister _rng w/ Float64: |
75 |
| - # # 21.333 ns (0 allocations: 0 bytes) |
76 |
| - # # rand() using Xoroshiro128Plus _rng w/ Float64: |
77 |
| - # # 19.716 ns (0 allocations: 0 bytes) |
78 |
| - # random_vec3_in_sphere(Float64) |
79 |
| - |
| 69 | + @test (@ballocated random_vec3_in_sphere(Float64)) == 0 # 19.716 ns |
| 70 | + |
80 | 71 | # "Random unit vector. Equivalent to C++'s `unit_vector(random_in_unit_sphere())`"
|
81 | 72 | # @inline random_vec3_on_sphere(::Type{T}) where T = normalize(random_vec3_in_sphere(T))
|
82 | 73 |
|
|
0 commit comments