With pragmas, I am getting 0.4s on a 2012 rMBP (macOS 10.14, Xojo 2018r3)
Public Function fib(n as int32) as int32
#Pragma BackgroundTasks False
#Pragma BoundsChecking False
#Pragma BreakOnExceptions False
#Pragma NilObjectChecking False
#Pragma StackOverflowChecking False
return if( n < 2, n, fib( n - 1 ) + fib( n - 2 ) )
End Function
Ha ha ! Yeah I love the speed I get from Objective-C, but when Xcode gives a new error that I’ve never seen before, and I can’t find any information about it online…
Or when I’m trying to build custom CIPlugins with a modern Xcode, because it no longer has the CIPlugin template, man that took ages to figure out all of the settings across the 30 odd pages.
i timed 2 things
total app time and time to run fib (you can see that by my posts way back)
I used this to get "total run to stop time perl -MTime::HiRes=time -e 'printf "%.9f\n", time' ; <<insert cmd line to run your app here>> ; perl -MTime::HiRes=time -e 'printf "%.9f\n", time'
Optimizing is really really hard. Back in 2017, I prototyped a new image processing algorithm in a weekend. It did exactly what I wanted, but it took 10 minutes to process a 20 megapixel image.
By Summer 2018, I’d got that down to 2 seconds, but it was creating terrible artifacts.
By Spring 2019, I’d gotten it down to 10 seconds, with a lot less artifacts, and a lot of GPU hacks.
Right now, it’s down to about 4 seconds on unreleased code and the closest results to the original yet, I even have an idea that might save a microsecond per iteration.
Sadly, I could have optimized it a lot quicker if Apple had allowed me to use shared constants across shaders, but they don’t they nor have they any interest in doing so, which forces me to incur far more reads on a textures. Which is supported in newer versions of OpenGL or DirectX, but not in Metal.
Measuring just the Fib method (not app startup or shutdown) I got 42,168.27 microseconds for Fib(35) in a console app with pragmas and aggressive compilation on a iMac Mojave 2019 i9
The run method was just this:
Dim result as Integer
Dim s as Double = Microseconds
result = fib(35)
Print(Str(Microseconds - S))