mathematical calculation

Blitz3D Forums/Blitz3D Programming/mathematical calculation

Eole(Posted 2003) [#1]
What is more quickly, mathematical calculation in Blitz or in C++ DLL ?

thank


soja(Posted 2003) [#2]
I'm no expert, but it seems to me that if you had to make an external function call (to a DLL) for every mathematical calculation, that would be slower than internal code... can anybody confirm or deny?

(This is all assuming the C++ compiler is good in the first place...)


Eole(Posted 2003) [#3]
It's for mathematica calculation like this (who can call a each frame)

_Point_Distance( x1 ,y1 , z1 , x2 ,y2 ,z2 )
-PointAngleCamera( xcam,ycam,zcam,angle )

etc . . .

Calculation with cos sqr etc . . .


Ross C(Posted 2003) [#4]
Well if i remember correctly code in blitz like maths and loops and types, are all complied straight into machine code, where-as things like drawimage, things relating to graphics use calls to external files.


Eole(Posted 2003) [#5]
Excuse me, but I'm english is not very good, so what is the best solution . . .


Rottbott(Posted 2003) [#6]
Not a DLL. Use Blitz code for this.


ChrML(Posted 2003) [#7]
I would say calling an external DLL for each mathematic calculation would definitly be slower. It must read it from the harddrive, execute it, and then wait for result. Muccch slower...


Bot Builder(Posted 2003) [#8]
ouch. Halo should here this. he's using dlls for alot of his math. maybe they should be converted to bb?


Koriolis(Posted 2003) [#9]
They definitely should. Putting so many simple and short function in DLLs is silly.
A correction to hyperblitzer though: it doesn't have to read from the hard drive each time it executes the function! DLLs would be a bag of *+# if it worked like that. DLLs are loaded and mapped in the process memory space. In short, once loaded it's stays in memory and acts *almost* (the calling in itself is only sligltly slower) just as if the functions were put directly in the app.

Eole, if you want a speed up, DLLs can be worth it if you use them to create functions that do a fair amount of work, and you optimize them carefully. But don't use DLLs to replace sin cos or little computations like that. You'll waste your time, and it's very likely to be slower.


Tom(Posted 2003) [#10]
I wrote my own 3d math library for easier vector access

type vec
field x#,y#,z#
end type
a.vec=new vec
b.vec=new vec

SetVec a,1.2,5.6,1.7
SetVec b,3.2,1.3,5.7

AddVector(a,b)

e.t.c

The speed up varies on the command used, if I remember correctly some functions are upto 15% - 20% faster, especialy ones that use more than a few lines of math, like point/plane equations.

So there can be a noticable speed up in using DLLs

Tom


podperson(Posted 2003) [#11]
Chances are unless you're doing a TON of these calculations, Blitz won't slow you down any. If you're really trying to optimize then were you writing in C++ you'd use inlines for which there's no equivalent in Blitz -- the closest equivalent would be to write entire subroutines in C++.


Eole(Posted 2003) [#12]
Thank