Corretto programma di benchmark

git-svn-id: svn://10.65.10.50/trunk@3802 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 1996-10-21 10:38:16 +00:00
parent cc196d4c93
commit dd01903edd

View File

@ -88,7 +88,7 @@ bool TTest_application::menu(MENU_TAG)
class TBenchmark_application : public TApplication
{
TIndwin* _iw;
clock_t _timer;
clock_t _timer_start;
protected:
virtual bool create();
@ -100,6 +100,7 @@ protected:
void stop_test();
void test_relation_scan();
void test_cursor_scan();
public:
TBenchmark_application() : _iw(NULL) { }
@ -126,43 +127,48 @@ bool TBenchmark_application::destroy()
bool TBenchmark_application::menu(MENU_TAG)
{
TString test = argv(1); test.upper();
const bool test_all = test.find('A') >= 0;
const bool test_all = test.find('*') >= 0;
if (test_all || test.find('R') >= 0)
test_relation_scan();
if (test_all || test.find('C') >= 0)
test_cursor_scan();
return TRUE;
}
void TBenchmark_application::initializing()
{
CHECK(_iw == NULL, "Benchmark already in progress");
_iw = new TIndwin(48, "Initializing ...", FALSE, TRUE, 48);
_iw = new TIndwin(48, "Initializing ...", TRUE, FALSE, 48);
}
void TBenchmark_application::start_test(const char* text)
{
CHECK(_iw != NULL, "Benchmark not started yet");
_iw->set_text(text);
do_events();
clock_t _timer = clock(), t;
clock_t t;
_timer_start = clock();
do
{
t = clock();
} while (t == _timer);
_timer = t;
} while (t == _timer_start);
_timer_start = t;
}
void TBenchmark_application::stop_test()
{
CHECK(_iw != NULL, "Benchmark not started yet");
const clock_t t = clock() - _timer;
const clock_t t = clock() - _timer_start;
const double s = t / CLOCKS_PER_SEC;
TString80 msg;
msg.format("Time to complete: %.1lf s", s);
_iw->set_text(msg);
while (!_iw->is_cancelled())
while (!_iw->iscancelled())
do_events();
delete _iw;
@ -177,7 +183,7 @@ void TBenchmark_application::test_relation_scan()
comuni.add("%UID", "CODTAB=UFFIIDD1");
comuni.first();
start_test("Scansione COMUNI+%UID");
start_test("Scansione relazione COMUNI+%UID");
while (!comuni.eof())
comuni.next();
@ -185,35 +191,41 @@ void TBenchmark_application::test_relation_scan()
stop_test();
}
void TBenchmark_application::test_cursor_scan()
{
initializing();
TRelation comuni(LF_COMUNI);
comuni.add("%UID", "CODTAB=UFFIIDD1");
TCursor cur(&comuni);
cur = 0L;
start_test("Scansione cursore COMUNI+%UID");
while (cur.ok())
++cur;
stop_test();
}
///////////////////////////////////////////////////////////
int main(int argc, char** argv)
{
TApplication::check_parameters(argc, argv);
if (argc > 1 && *argv[0] == '-')
if (argc > 1 && *argv[1] == '-')
{
TBenchmark_application bma;
bma.run();
bma.run(argc, argv, "Benchmark");
return 0;
}
if (argc < 3)
{
TFilename n;
if (argc == 1)
{
TMask m("Inserire il nome della maschera", 1, 42, 4);
m.add_string(101, 0, "", 1, 1, 40);
m.field(101).check_type(CHECK_REQUIRED);
m.add_button(DLG_OK, 0, "", -12, -1, 10, 2);
m.add_button(DLG_CANCEL, 0, "", -22, -1, 10, 2);
if (m.run() == K_ENTER)
n = m.get(101);
}
else
n = argv[1];
TFilename n = argv[1];
if (n.not_empty())
{
TTest_application a(n);