119 lines
2.6 KiB
C++
119 lines
2.6 KiB
C++
/*
|
|
BlockPlanet
|
|
Copyright (C) 2012 MiJyn, Joel Leclerc <mijyn@mail.com>
|
|
Licensed under GPLv3
|
|
|
|
|
|
Based on:
|
|
Minetest-c55
|
|
Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License along
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
*/
|
|
|
|
#include "speedtests.h"
|
|
#include "common_irrlicht.h"
|
|
#include "utility.h"
|
|
#include "log.h"
|
|
|
|
void SpeedTest::SpeedTests()
|
|
{
|
|
{
|
|
infostream<<"The following test should take around 20ms."<<std::endl;
|
|
TimeTaker timer("Testing std::string speed");
|
|
const u32 jj = 10000;
|
|
for(u32 j=0; j<jj; j++)
|
|
{
|
|
tempstring = "";
|
|
tempstring2 = "";
|
|
const u32 ii = 10;
|
|
for(u32 i=0; i<ii; i++){
|
|
tempstring2 += "asd";
|
|
}
|
|
for(u32 i=0; i<ii+1; i++){
|
|
tempstring += "asd";
|
|
if(tempstring == tempstring2)
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
infostream<<"All of the following tests should take around 100ms each."
|
|
<<std::endl;
|
|
|
|
{
|
|
TimeTaker timer("Testing floating-point conversion speed");
|
|
tempf = 0.001;
|
|
for(u32 i=0; i<4000000; i++){
|
|
temp16 += tempf;
|
|
tempf += 0.001;
|
|
}
|
|
}
|
|
|
|
{
|
|
TimeTaker timer("Testing floating-point vector speed");
|
|
|
|
tempv3f1 = v3f(1,2,3);
|
|
tempv3f2 = v3f(4,5,6);
|
|
for(u32 i=0; i<10000000; i++){
|
|
tempf += tempv3f1.dotProduct(tempv3f2);
|
|
tempv3f2 += v3f(7,8,9);
|
|
}
|
|
}
|
|
|
|
{
|
|
TimeTaker timer("Testing core::map speed");
|
|
|
|
core::map<v2s16, f32> map1;
|
|
tempf = -324;
|
|
const s16 ii=300;
|
|
for(s16 y=0; y<ii; y++){
|
|
for(s16 x=0; x<ii; x++){
|
|
map1.insert(v2s16(x,y), tempf);
|
|
tempf += 1;
|
|
}
|
|
}
|
|
for(s16 y=ii-1; y>=0; y--){
|
|
for(s16 x=0; x<ii; x++){
|
|
tempf = map1[v2s16(x,y)];
|
|
}
|
|
}
|
|
}
|
|
|
|
{
|
|
infostream<<"Around 5000/ms should do well here."<<std::endl;
|
|
TimeTaker timer("Testing mutex speed");
|
|
|
|
JMutex m;
|
|
m.Init();
|
|
u32 n = 0;
|
|
u32 i = 0;
|
|
do{
|
|
n += 10000;
|
|
for(; i<n; i++){
|
|
m.Lock();
|
|
m.Unlock();
|
|
}
|
|
}
|
|
// Do at least 10ms
|
|
while(timer.getTime() < 10);
|
|
|
|
u32 dtime = timer.stop();
|
|
u32 per_ms = n / dtime;
|
|
infostream<<"Done. "<<dtime<<"ms, "
|
|
<<per_ms<<"/ms"<<std::endl;
|
|
}
|
|
}
|