Heres a simple test I did which creates simply copies 44100 floats from one
memoryblock to another.  It does this 3000 times in order to allow timing to
be done.

I did this initially to see if there is a significant performance gain from
using Ptr pointers to the memoryblocks to do the reads and copies, versus
using the memoryblock SingleValue() methods.

Indeed there is. Using Ptr is faster.

But out of curiosity I thought I'd see how near the performance was compared
to doing the core copy operation in C - using a dylib. So I wrote a quick
dylib with a single function:

void copySingle (int count, float * A, float * B ) {
   int i;
   for ( i = 0; i < count ; i++ )  {
      B[i] = A[i];
   }
};


And then via a declare called this function 3000 times. ( passing 3000 as
the count argument )

The time taken in RB using Ptr:  around 45 seconds
And in by calling the C dylib ? :   5 seconds.

This is on a G4 PowerBook.

I was NOT expecting that, and that 45 second timing was even after using
pragmas to reduce overheads.

I was expecting RB to be a little slower than C but not  THAT much slower.
After all - RB is supposed to be natively compiled - thus comparable to C.

Here is the code for the RB version:
****************************************************************

  #pragma DisableAutoWaitCursor
  #pragma DisableBackgroundTasks
  #pragma DisableBoundsChecking
  #pragma StackOverflowChecking false
  
  Dim Count As integer = 44100 -1
  DIm iterations as integer = 3000
  
  // source buffer
  Dim A as new MemoryBlock( 44100 * 4)
  
  // stuff A with incrementing single values
  for i as integer = 0 to Count
    A.SingleValue(i*4) = i
  Next
  
  // target buffer
  Dim B as new MemoryBlock( 44100 * 4)
  
  // use pointers for speed
  dim pA As Ptr = A
  dim pB as Ptr = B
  
  Result.Text = "Started"
  app.DoEvents
  
  dim u as integer = Count * 4
  for j as integer = 0 to iterations
    for i as integer = 0 to u step 4
      pB.Single(i) = pA.Single(i)
    Next
  Next
  
  Beep
  
  Result.Text= "FINISHED"

*************************************
And here is the version that calls the C function in the dylib:

  
  soft Declare Sub copySingle  Lib LIBPATH ( c as integer, ptA as Ptr, ptB
as Ptr )
  
  Dim Count As integer = 44100
  DIm iterations as integer = 3000
  
  Dim A as new MemoryBlock( 44100 * 4)
  
  // stuff A with incrementing single values
  for i as integer = 0 to Count-1
    A.SingleValue(i*4) = i
  Next
  
  Dim B as new MemoryBlock( 44100 * 4)
  
  dim pA As Ptr = A
  dim pB as Ptr = B
  
  Result.Text = "Started"
  app.DoEvents
  
  dim u as integer = Count
  for j as integer = 0 to iterations
    copySingle( u, pA, pB )
  Next
  
  Beep
  Result.Text= "FINISHED"



So - here is the 40 million dollar question - WHY is RB nearly 10 times
slower than C ?
Is this something that can and should be adressed by RS ?  


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

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to