I've written something that uses my JSON library to read and write save files. The JSON decoder uses a lot of functions which take arrays as arguments, and parsing a ~1mb file takes over two minutes. So, lots of optimisations to be made, and I thought I'd start with seeing if passing arrays around was a bottleneck.
Here's a test:
In the first test, the function refers to the array directly, it is not passed in as an argument.
In the second test, an array is passed in, but it is always the same global array object.
In the third test, the array is created inside the function call, so it is created every time the function is called, as blitz can't do constant arrays.
Here are my results, with debug on:
and with debug off:
(As an aside, turning superstrict off when debug build is enabled makes it run much faster. That seems odd to me.)
So, clearly, initialising arrays takes a lot of time. Can't bmk be made to recognise arrays consisting solely of string/number literals and only initialise them once? I can see it would probably take a little bit more analysis when building, but I think it'd be worth it.
PS While I'm here, can anyone think of a way of writing a generic function to get the next character in a string belonging to a certain set which *doesn't* involve using arrays?
Here's a test:
SuperStrict Function f1:Int(arr:Int[]) Local t:Int,i:Int t:Int=0 For i:Int=EachIn arr t:+i Next Return t End Function Function f1local() f1([1,2,3]) End Function Global carr:Int[]=[1,2,3] Function f1const() f1(carr) End Function Function f2const:Int() Local t:Int,i:Int t:Int=0 For i:Int=EachIn carr t:+i Next Return t End Function Function time(func:Int(),name$) Local oms:Int,ms:Int,c:Int oms:Int=MilliSecs() For c:Int=1 To 10000000 func Next ms:Int=MilliSecs() Print name+" took "+(ms-oms)/1000.0+" seconds" End Function time f2const,"don't pass const array" time f1const,"pass array, const" time f1local,"pass array, local"
In the first test, the function refers to the array directly, it is not passed in as an argument.
In the second test, an array is passed in, but it is always the same global array object.
In the third test, the array is created inside the function call, so it is created every time the function is called, as blitz can't do constant arrays.
Here are my results, with debug on:
don't pass const array took 5.81400013 seconds pass array, const took 5.87099981 seconds pass array, local took 8.67500019 seconds
and with debug off:
don't pass const array took 0.254000008 seconds pass array, const took 0.310000002 seconds pass array, local took 3.26399994 seconds
(As an aside, turning superstrict off when debug build is enabled makes it run much faster. That seems odd to me.)
So, clearly, initialising arrays takes a lot of time. Can't bmk be made to recognise arrays consisting solely of string/number literals and only initialise them once? I can see it would probably take a little bit more analysis when building, but I think it'd be worth it.
PS While I'm here, can anyone think of a way of writing a generic function to get the next character in a string belonging to a certain set which *doesn't* involve using arrays?