Commit 2b20e1c
committed
lib: specialize radical_inverse() for improved performance
I re-read the PBRT section on sampling, and realised my original C port
of their radical inverse implementation misses on the performance
benefits of the C++ template trick they use.
Recreate the same trick with some X macros, the improvement seems
noticeable. On my desktop (i7-6700k, 4c/8t):
Before:
> hyperfine 'bin/c-ray input/hdr.json --no-sdl -s 128'
Benchmark 1: bin/c-ray input/hdr.json --no-sdl -s 128
Time (mean ± σ): 27.379 s ± 0.548 s [User: 189.460 s, System: 0.589 s]
Range (min … max): 26.518 s … 28.056 s 10 runs
After:
> hyperfine 'bin/c-ray input/hdr.json --no-sdl -s 128'
Benchmark 1: bin/c-ray input/hdr.json --no-sdl -s 128
Time (mean ± σ): 25.778 s ± 0.592 s [User: 177.314 s, System: 0.534 s]
Range (min … max): 24.894 s … 26.677 s 10 runs
On my server (AMD EPYC 9374F, 32c/64t):
Before:
> hyperfine 'bin/c-ray input/hdr.json --no-sdl -s 1024 -j 64'
Benchmark 1: bin/c-ray input/hdr.json --no-sdl -s 1024 -j 64
Time (mean ± σ): 20.264 s ± 0.142 s [User: 977.766 s, System: 0.292 s]
Range (min … max): 20.055 s … 20.551 s 10 runs
After:
> hyperfine 'bin/c-ray input/hdr.json --no-sdl -s 1024 -j 64'
Benchmark 1: bin/c-ray input/hdr.json --no-sdl -s 1024 -j 64
Time (mean ± σ): 19.989 s ± 0.119 s [User: 954.135 s, System: 0.275 s]
Range (min … max): 19.836 s … 20.157 s 10 runs1 parent 9a6861f commit 2b20e1c
3 files changed
+60
-16
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
44 | 88 | | |
45 | | - | |
| 89 | + | |
| 90 | + | |
46 | 91 | | |
| 92 | + | |
47 | 93 | | |
48 | 94 | | |
49 | 95 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | 16 | | |
18 | 17 | | |
19 | 18 | | |
| |||
24 | 23 | | |
25 | 24 | | |
26 | 25 | | |
27 | | - | |
| 26 | + | |
28 | 27 | | |
29 | 28 | | |
30 | 29 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | 16 | | |
18 | 17 | | |
19 | 18 | | |
| |||
28 | 27 | | |
29 | 28 | | |
30 | 29 | | |
31 | | - | |
| 30 | + | |
32 | 31 | | |
33 | 32 | | |
34 | 33 | | |
| |||
0 commit comments