On Sep 26, 2006, at 12:28 PM, Charles Yeomans wrote:


I did the following simple test.

  dim start as Double = Microseconds

  dim m as new MemoryBlock(1024*1024)
  dim p as Ptr = m
  dim n as Integer = m.Size - 1

  for i as Integer = 0 to n step 4
    dim c as Integer = p.Int32
    p = p + ptr(4)
  next

  dim stop as Double = Microseconds

  MsgBox Format(stop - start, "#")

On my Mac mini, this code took about 31400 microseconds to execute, on average. So did this version.

  dim m as new MemoryBlock(1024*1024)
  dim p as Ptr = m
  dim n as Integer = m.Size - 1

  for i as Integer = 0 to n step 4
    dim c as Integer = p.Int32(i)
  next


This code, which just uses the MemoryBlock for access, took about 39500 microseconds.

  dim m as new MemoryBlock(1024*1024)
  dim n as Integer = m.Size - 1

  for i as Integer = 0 to n step 4
    dim c as Integer = m.Int32Value(i)
  next


The effect of disabling background tasks using #pragma disableBackgroundTasks was surprising. The execution time of code snippet 1 dropped to 5000 microseconds. But the execution time of code snippet 2 dropped to 3600 microseconds. Rewriting code snippet 1 as follows improved its execution time to 4200 microseconds -- still an apparently significant difference.

  dim m as new MemoryBlock(1024*1024)
  dim p as Ptr = m
  dim n as Integer = m.Size - 1
  dim offset as Ptr = Ptr(4)

  for i as Integer = 0 to n step 4
    dim c as Integer = p.Int32
    p = p + offset
  next

Perhaps this is indicative of something...

Well, Mars has been giving me a few pointers (gawd that was horrible... sorry) on how to use ptrs best, and he said casting an integer to a ptr is a fairly expensive operation, so you're better off using the offset rather than incrementing the ptr itself. he also said there are speed up to be had working with offsets of 0 or constants - no surprise there. but from my experimentation your snippet 1 will be about the fastest we can get at this point.

mike
--
Mike Woodworth
[EMAIL PROTECTED]



_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to