4x to 5x speed boost for data processing
-
So, I was investigating if Fuze supports some kind of parallel processing, and while I couldn't find much, there IS this:
x = 12345 vector x2 = {12345, 12346, 12347, 12348} vector y2 start = time() for i = 0 to 1000000 loop y = x*x repeat end = time() start2 = time() for i = 0 to 1000000/4 loop y2 = x2*x2 repeat end2 = time() print("First: ", end - start, "\nSecond: ", end2 - start2) update() loop repeat
The second way of doing things takes roughly 4 to 5 times less time than the first. Now I know this is a very simplistic way of doing things, but this could be pretty exciting in situations where a large number of repetitive calculations is required!
Tell me what you think!
Caveats: this doesn't work with built-in functions, it also requires y2 in this situation to be declared beforehand.
-
Oh, and more testing could be required because it's possible that optimizations cause the multiplications to be run only once and the time is used up by the loops alone.
-
@Doriphor probably my day was already too long, but is this a typo?
1000000/4
or why not using the same as in the first loop? Nevertheless it could be that the second loop does not need to allocate new memory, thats why its quicker, but probably this what you discovered already. I am just guessing. -
What is the resulting vector? Is it the the dot product? Or...
If it is {x2.x * x2.x, x2.y * x2.y, etc} then, yes, that does seem to be a more efficient way of doing lots of multiplication operations.
An interesting find...
-
-
Neat idea! The second works faster because FUZE is an interpreted language. While it's still performing the same number of multiplications, it's passing data more efficiently to the native code since you're giving it 4 numbers at a time instead of 1 number. That means less interpreted instructions overall, which are slower than equivalent native code.
-
@Willpowered I figured it was either that or conditional jumps take a lot of time 🤔