[sword-devel] Your speed is great!
Victor Porton
sword-devel@crosswire.org
Sat, 08 Jun 2002 23:39:02 +0600
The speed of Sword is great!
On Pentium 166
$ ./speed
20000 cycles for 16.37 seconds (One cycle per 0.0008185 sec).
I suggest to add the following program to the tests:
#include <stdlib.h>
#include <iostream.h>
#include <time.h>
#include <swmgr.h>
#include <swld.h>
int main(int argc, char **argv)
{
const char *modname = argc<2 ? "BDB" : argv[1];
SWMgr mymgr;
SWLD *mod = (SWLD*)mymgr.Modules[modname];
if (!mod) {
std::cerr << "Module " << modname << " is not installed!" << std::endl;
return EXIT_FAILURE;
}
clock_t sum = 0;
const int numCycles = 20000;
for(int i=0; i<numCycles; ++i) {
int num = 1+(int) (8853.0*rand()/(RAND_MAX+1.0));
char buf[5];
sprintf(buf, "%d", num);
clock_t begintime = clock();
mod->SetKey(StrKey(buf));
mod->getRawEntry();
clock_t endtime = clock();
sum += endtime - begintime;
}
float time = (float)sum/CLOCKS_PER_SEC;
std::cout << numCycles <<" cycles for " << time <<
" seconds (One cycle per " << time/numCycles << " sec)." << std::endl;
}
--
Victor Porton (porton@narod.ru)