New Framework and MemoryBlock

OK I have had time to convert my math modules to using the new framework. All testing that I have done is on the Mac. For the most part the new framework looks to be faster regarding memoryblock methods. For instance the .left and .append methods appear to be quite a bit faster with the new framework. However, I still have two use cases where using the old framework is much faster. The first is clearing a range of bytes in the middle of a memoryblock and the other is moving a block of bytes from the middle of one memoryblock to another. I have included some test code below to show the difference. The first use case is about 15 times slower with the new framework and the second is about three times slower (see variables factor1 and factor2). If there is a faster way to accomplish either case in the new framework I would appreciate feedback.

On another note, I am seeing that the overall code that I converted is about 10% slower with the new framework. At this point I am still trying to figure out why. I have profiled the code and the methods that are slower were not even modified. They do have extensive use of .double pointer methods (pointing to new framework memory blocks) but specifically testing that functionality in test code shows that the new framework is actually faster so I am scratching my head. The routines in question are very math intensive so I suspect that has something to do with it. The routines are forward and inverse fast fourier transforms.

[code] // new framework vs old
dim time1, time2, time3, factor1, factor2 as double
dim mb1 as new MemoryBlock(100000)
dim mb2 as new MemoryBlock(100000)
dim mb3 as new xojo.Core.MutableMemoryBlock(100000)
dim mb4 as new xojo.Core.MutableMemoryBlock(100000)
dim loop1, loop2 as integer

// clear bytes using old framework
for loop1 = 0 to 99999
mb1.Int8Value(loop1) = 9
next
for loop2 = 1 to 1000
time1 = Microseconds
mb1.StringValue(80000,20000) = “”
time1 = Microseconds - time1
time2 = time2 + time1
next

// clear bytes using new framework
for loop1 = 0 to 99999
mb1.Int8Value(loop1) = 9
next
for loop2 = 1 to 1000
time1 = Microseconds
mb3.mid(80000,20000) = new xojo.Core.MemoryBlock(20000)
time1 = Microseconds - time1
time3 = time3 + time1
next

factor1 = time3 / time2

// mid old framework
time2 = 0.
for loop2 = 1 to 1000
time1 = Microseconds
mb1.StringValue(10000,10000) = mb2.MidB(20000,10000)
time1 = Microseconds - time1
time2 = time2 + time1
next

// mid new framework
time3 = 0.
for loop2 = 1 to 1000
time1 = Microseconds
mb3.mid(10000,10000) = mb4.mid(20000,10000)
time1 = Microseconds - time1
time3 = time3 + time1
next

factor2 = time3 / time2[/code]

First optimization I eyeball right off the bat- don’t recreate a new memoryblock everytime in a loop- instead create it outside of the loop once and reuse it, like:

dim zeromb as new xojo.Core.MemoryBlock(20000) for loop2 = 1 to 1000 time1 = Microseconds mb3.mid(80000,20000) = zeromb time1 = Microseconds - time1 time3 = time3 + time1 next

Travis, the loops are only there to average out over number of iterations. My production code does not loop like this. I believe the code does fairly compare the speed of the two frameworks doing the same functions. There is quite a bit of variability in the timing and the loops were to try to average that out for testing purposes.

Noted- but in general to anyone reading if there is a case where you would replace the same number (or sets of the same numbers) of bytes like the example above, you should just create those blocks once and reuse them.