Is this an issue?
#1
Hi all,

I was looking at creating C/C++ Dll's to add functionality to QB64PE, and I was doing timings to see what would be best done in a dll vs native to QB64PE and I got some results that confused me.

I have a simple c function I created which adds 2 numbers:

int Add(int a, int b)
{
  return (a + b);
}

I have a QB64PE function that does the same as the c function:

Function addit% (a%, b%)
    addit% = a% + b%
End Function


and as a baseline/control I do inline addition, each is done in a loop (500000000 times).

The results gave me pause:

Dll - 7.25 seconds
inline - 5.38 seconds
internal function - 41.16 seconds

I expected that the internal function would be between the dll and inline in timing.  Why would calling external to a dll to a function to add 2 numbers be quicker than calling internal to a function to add 2 numbers?


My code:

' dll test
Declare Dynamic Library "c:\users\bob\qb64\mydll"
    Function Add% (ByVal a As Integer, Byval b As Integer) 'SDL procedure name
End Declare

f% = 6
e% = 23

Locate 2, 1
Print "external dll call";

Locate 4, 1
Print "QB64PE inline addition";

Locate 6, 1
Print "QB64PE internal function";

a = Timer
For x& = 1 To 500000000
    k% = Add%(f%, e%)
Next
b = Timer

Locate 1, 1
Print Using "##.##########"; (b - a);

c = Timer
For x& = 1 To 500000000
    k% = f% + e%
Next
d = Timer

Locate 3, 1
Print Using "##.##########"; (d - c);

g = Timer
For x& = 1 To 500000000
    k% = addit%(f%, e%)
Next
h = Timer

Locate 5, 1
Print Using "##.##########"; (h - g);

End

Function addit% (a%, b%)
    addit% = a% + b%
End Function

If you want the c code for the dll let me know.
Reply


Messages In This Thread
Is this an issue? - by bobkreid - 07-01-2022, 07:56 PM
RE: Is this an issue? - by bplus - 07-01-2022, 11:00 PM
RE: Is this an issue? - by Kernelpanic - 07-01-2022, 11:42 PM
RE: Is this an issue? - by Kernelpanic - 07-01-2022, 11:57 PM
RE: Is this an issue? - by DSMan195276 - 07-02-2022, 12:32 AM
RE: Is this an issue? - by bobkreid - 07-03-2022, 10:27 AM
RE: Is this an issue? - by SMcNeill - 07-02-2022, 01:10 AM
RE: Is this an issue? - by bobkreid - 07-03-2022, 10:35 AM
RE: Is this an issue? - by madscijr - 07-02-2022, 09:35 PM
RE: Is this an issue? - by DSMan195276 - 07-03-2022, 05:48 AM
RE: Is this an issue? - by madscijr - 07-03-2022, 03:05 PM
RE: Is this an issue? - by DSMan195276 - 07-04-2022, 03:48 AM



Users browsing this thread: 6 Guest(s)