hello
I'm making 2D physics engine with Blitzmax.
But, it is too slow to use "type vector2d" made with blitzmax.
The task that numerous vectors are generated and destroyed for a loop is too slow.
I think that this task is slower than another task with C++ by 100 times.
The automatic memory management of blitzmax is very useful, but slow for this kind of task.
I tried to use not "user defined type" but combination of array ptr. and functions,
but array is processed like "user defined type" too.
I'd like to use data structure constructed by 2 float number.
Can I make directly referenced struct in Bmax? I don't care if it is in OOP or not.
The source below is for test. The elapsed times to process this are about 0ms in C++, and 56ms in Bmax. Oh my god.
--------------------------------- c++ source ------------------------------------------
#include <iostream>
#include <ctime>
#include <conio.h>
class Vector {
public:
float x;
float y;
Vector(void);
Vector(float xi, float yi);
};
inline Vector::Vector (void)
{
x=0;
y=0;
}
inline Vector::Vector(float xi, float yi)
{
x=xi;
y=yi;
}
inline Vector operator+(Vector u, Vector v)
{
return Vector(u.x + v.x, u.y + v.y);
}
int main()
{
int const ITERATIONS = 100000;
long t = std::clock();
int loop;
Vector A = Vector(3,3);
Vector B = Vector(2,5);
Vector C = Vector (0,0);
for (loop = 0 ; loop < ITERATIONS ; loop++ )
{
Vector A = Vector(1,2);
Vector B = Vector(3,4);
Vector C ;
C=A+B;
}
t = std::clock() - t;
std::cout << ITERATIONS << " iterations took " << t << " millisecs.\n";
getch();
return 0;
}
------------------------------BMAX source------------------------------------------
Type tVec
Field x : Float
Field y : Float
Method add : tvec( _v : tvec)
Local v : tVec = New tvec
v.x=self.x+_v.x
v.y=self.y+_v.y
Return v
EndMethod
Function create : tvec (_x#=0.0,_y#=0.0)
Local v: tvec = New tvec
v.x=_x
v.y=_y
Return v
EndFunction
EndType
Const ITERATIONS = 100000
Local t = MilliSecs()
For Local i = 0 To ITERATIONS
Local va: tvec = tvec.create(3,3)
Local vb : tvec = tvec.create(3 , 4)
Local vc : tvec
vc = va.add(vb)
Next
Print ITERATIONS + " iterations took " + (MilliSecs() - t) +" millisecs."
I'm making 2D physics engine with Blitzmax.
But, it is too slow to use "type vector2d" made with blitzmax.
The task that numerous vectors are generated and destroyed for a loop is too slow.
I think that this task is slower than another task with C++ by 100 times.
The automatic memory management of blitzmax is very useful, but slow for this kind of task.
I tried to use not "user defined type" but combination of array ptr. and functions,
but array is processed like "user defined type" too.
I'd like to use data structure constructed by 2 float number.
Can I make directly referenced struct in Bmax? I don't care if it is in OOP or not.
The source below is for test. The elapsed times to process this are about 0ms in C++, and 56ms in Bmax. Oh my god.
--------------------------------- c++ source ------------------------------------------
#include <iostream>
#include <ctime>
#include <conio.h>
class Vector {
public:
float x;
float y;
Vector(void);
Vector(float xi, float yi);
};
inline Vector::Vector (void)
{
x=0;
y=0;
}
inline Vector::Vector(float xi, float yi)
{
x=xi;
y=yi;
}
inline Vector operator+(Vector u, Vector v)
{
return Vector(u.x + v.x, u.y + v.y);
}
int main()
{
int const ITERATIONS = 100000;
long t = std::clock();
int loop;
Vector A = Vector(3,3);
Vector B = Vector(2,5);
Vector C = Vector (0,0);
for (loop = 0 ; loop < ITERATIONS ; loop++ )
{
Vector A = Vector(1,2);
Vector B = Vector(3,4);
Vector C ;
C=A+B;
}
t = std::clock() - t;
std::cout << ITERATIONS << " iterations took " << t << " millisecs.\n";
getch();
return 0;
}
------------------------------BMAX source------------------------------------------
Type tVec
Field x : Float
Field y : Float
Method add : tvec( _v : tvec)
Local v : tVec = New tvec
v.x=self.x+_v.x
v.y=self.y+_v.y
Return v
EndMethod
Function create : tvec (_x#=0.0,_y#=0.0)
Local v: tvec = New tvec
v.x=_x
v.y=_y
Return v
EndFunction
EndType
Const ITERATIONS = 100000
Local t = MilliSecs()
For Local i = 0 To ITERATIONS
Local va: tvec = tvec.create(3,3)
Local vb : tvec = tvec.create(3 , 4)
Local vc : tvec
vc = va.add(vb)
Next
Print ITERATIONS + " iterations took " + (MilliSecs() - t) +" millisecs."