Migliorato benchmark

git-svn-id: svn://10.65.10.50/trunk@3953 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 1996-12-03 09:20:48 +00:00
parent 972e56a4bd
commit 5678846ebd

View File

@ -1,6 +1,5 @@
#include <time.h> #include <time.h>
#include <progind.h>
#include <relapp.h> #include <relapp.h>
#include <urldefid.h> #include <urldefid.h>
@ -161,7 +160,6 @@ bool TTest_application::menu(MENU_TAG)
class TBenchmark_application : public TApplication class TBenchmark_application : public TApplication
{ {
TIndwin* _iw;
clock_t _timer_start; clock_t _timer_start;
protected: protected:
@ -171,57 +169,54 @@ protected:
void initializing(); void initializing();
void start_test(const char* msg); void start_test(const char* msg);
void update_bar(long rec);
void stop_test(); void stop_test();
void test_relation_scan(); void test_relation_scan();
void test_cursor_scan(); void test_cursor_scan();
public: public:
TBenchmark_application() : _iw(NULL) { } TBenchmark_application() { }
virtual ~TBenchmark_application() { } virtual ~TBenchmark_application() { }
}; };
bool TBenchmark_application::create() bool TBenchmark_application::create()
{ {
dispatch_e_menu(MENU_ITEM(1)); dispatch_e_menu(BAR_ITEM(1));
return TRUE; return TRUE;
} }
bool TBenchmark_application::destroy() bool TBenchmark_application::destroy()
{ {
if (_iw)
{
delete _iw;
_iw = NULL;
}
return TRUE; return TRUE;
} }
bool TBenchmark_application::menu(MENU_TAG) bool TBenchmark_application::menu(MENU_TAG mt)
{ {
TString test = argv(1); test.upper(); if (mt == BAR_ITEM(1))
const bool test_all = test.find('*') >= 0; {
TString test = argv(1); test.upper();
const bool test_all = test.find('*') >= 0;
if (test_all || test.find('R') >= 0) if (test_all || test.find('R') >= 0)
test_relation_scan(); test_relation_scan();
if (test_all || test.find('C') >= 0)
test_cursor_scan();
if (test_all || test.find('C') >= 0)
test_cursor_scan();
}
return TRUE; return TRUE;
} }
void TBenchmark_application::initializing() void TBenchmark_application::initializing()
{ {
CHECK(_iw == NULL, "Benchmark already in progress"); xvt_statbar_set("Initializing...");
_iw = new TIndwin(48, "Initializing ...", TRUE, FALSE, 48); do_events();
} }
void TBenchmark_application::start_test(const char* text) void TBenchmark_application::start_test(const char* text)
{ {
CHECK(_iw != NULL, "Benchmark not started yet"); xvt_statbar_set(text);
_iw->set_text(text);
do_events(); do_events();
clock_t t; clock_t t;
@ -235,18 +230,26 @@ void TBenchmark_application::start_test(const char* text)
void TBenchmark_application::stop_test() void TBenchmark_application::stop_test()
{ {
CHECK(_iw != NULL, "Benchmark not started yet");
const clock_t t = clock() - _timer_start; const clock_t t = clock() - _timer_start;
const double s = t / CLOCKS_PER_SEC; const double s = t / CLOCKS_PER_SEC;
TString80 msg; TString80 msg;
msg.format("Time to complete: %.1lf s", s); msg.format("Time to complete: %.1lf s", s);
_iw->set_text(msg); message_box(msg);
}
while (!_iw->iscancelled()) void TBenchmark_application::update_bar(long rec)
do_events(); {
if ((rec & 0x7F) == 0)
delete _iw; {
_iw = NULL; const double sec = double(clock() - _timer_start) / CLOCKS_PER_SEC;
if (sec > 0.0)
{
TString80 msg;
msg.format("%ld records at %ld rec/sec", rec, long(rec / sec));
xvt_statbar_set(msg);
do_events();
}
}
} }
void TBenchmark_application::test_relation_scan() void TBenchmark_application::test_relation_scan()
@ -259,8 +262,11 @@ void TBenchmark_application::test_relation_scan()
start_test("Scansione relazione COMUNI+%UID"); start_test("Scansione relazione COMUNI+%UID");
while (!comuni.eof()) for (TRecnotype rec = 0; !comuni.eof(); rec++)
{
comuni.next(); comuni.next();
update_bar(rec);
}
stop_test(); stop_test();
} }
@ -278,7 +284,10 @@ void TBenchmark_application::test_cursor_scan()
start_test("Scansione cursore COMUNI+%UID"); start_test("Scansione cursore COMUNI+%UID");
while (cur.ok()) while (cur.ok())
{
++cur; ++cur;
update_bar(cur.pos());
}
stop_test(); stop_test();
} }