Can someone correct me, where, or if I do something wrong in my test?
It looks in this test, main thread is faster than parallel for job with burst.
I must be missing something?
Testing timing of different branching approaches.
Using Unity 2020.1.3 Entities 0.14. But that shouldn’t make a difference.
Jobs Branching Timing test has following results:
Iterating 1 million of elements.
Main thread no burst
Branching using ? 2 ms
z = i > b ? i : b ;
No branching 5 ms
z = b ^ ((i ^ b) & -(i << b)) ;
No branching with if 6 ms
z = i ; if ( i <= b ) z = b ;
Branching if else 7 ms
if ( a > b ) { z = a ; } else { z = b ; }
Incorrect burst timing, as used BurstCompatible, instead BurstCompile :p:roll_eyes: Job Parallel For With burst (equivalent)
Branching using ? 9 ms
int a = i > na_i [1] ? i : na_i [1] ;
No branching 22 ms
int a = na_i [1] ^ ((i ^ na_i [1]) & -(i << na_i [1])) ;
No branching with if 10 ms
int a = i ;if ( i <= na_i [1] ) a = na_i [1] ;
Branching if else 10 ms
if ( i > na_i [1] ) { a = i ; } else { a = na_i [1] ; }
Github link to system base cs file.
In the system OnUpdates, repeating test after every Stop.
You are supposed to use math.select to avoid branching in burst. Though based on your results in this case burst might be smart enough to compile the ? case similarly.