93a4af8c3c
git-svn-id: svn://10.65.10.50/branches/R_10_00@22789 c028cbd2-c16b-5b4b-a496-9718f37d4682
483 lines
11 KiB
C++
Executable File
483 lines
11 KiB
C++
Executable File
#include <applicat.h>
|
|
#include <progind.h>
|
|
#include <recarray.h>
|
|
#include <relation.h>
|
|
#include <tabutil.h>
|
|
#include <toolfld.h>
|
|
#include <reputils.h>
|
|
#include <urldefid.h>
|
|
|
|
#include <comuni.h>
|
|
|
|
class TProfiler_mask : public TMask
|
|
{
|
|
public:
|
|
TProfiler_mask();
|
|
};
|
|
|
|
TProfiler_mask::TProfiler_mask() : TMask(TR("Test"), 1, 60, 14)
|
|
{
|
|
add_button_tool(DLG_OK, PR("Elabora"), TOOL_ELABORA);
|
|
add_button_tool(DLG_INFO, PR("Info"), TOOL_INFO);
|
|
add_button_tool(DLG_HELP, PR("Help"), TOOL_HELP);
|
|
add_button_tool(DLG_QUIT, "", TOOL_QUIT);
|
|
|
|
TToken_string codes, items;
|
|
codes.add(0); items.add(TR("Tutti i test"));
|
|
codes.add(1); items.add(TR("Lettura sequenziale tabella"));
|
|
codes.add(2); items.add(TR("Lettura cursore su chiave primaria"));
|
|
codes.add(3); items.add(TR("Lettura cursore con ordinamento fuori chiave"));
|
|
codes.add(4); items.add(TR("Lettura causale con cache"));
|
|
codes.add(5); items.add(TR("Lettura causale senza cache"));
|
|
codes.add(6); items.add(TR("Creazione e cancellazione records"));
|
|
codes.add(7); items.add(TR("Creazione e cancellazione records in modo esclusivo"));
|
|
add_radio(101, 0, TR("@bSelezione test"), 1, 1, 58, codes, items);
|
|
add_number(102, 0, PR("Numero di iterazioni"), 1, 0, 3, "U");
|
|
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Testfile
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TTest_application : public TSkeleton_application
|
|
{
|
|
TProgind* _pi;
|
|
|
|
clock_t start_timer() const;
|
|
|
|
clock_t start_progind(const long items, const char* prompt);
|
|
clock_t stop_progind();
|
|
|
|
protected:
|
|
bool test1(TLog_report& log);
|
|
bool test2(TLog_report& log);
|
|
bool test3(TLog_report& log);
|
|
bool test4(TLog_report& log);
|
|
bool test5(TLog_report& log);
|
|
bool test6(TLog_report& log);
|
|
bool test7(TLog_report& log);
|
|
|
|
public:
|
|
bool test(int n, TLog_report& log);
|
|
virtual void main_loop();
|
|
|
|
TTest_application() : _pi(NULL) { }
|
|
};
|
|
|
|
clock_t TTest_application::start_timer() const
|
|
{
|
|
clock_t t = clock();
|
|
while (clock() == t);
|
|
t = clock();
|
|
return t;
|
|
}
|
|
|
|
clock_t TTest_application::start_progind(const long items, const char* prompt)
|
|
{
|
|
CHECK(_pi == NULL, "Double progress indicator");
|
|
_pi = new TProgind(items, prompt, true, true);
|
|
return start_timer();
|
|
}
|
|
|
|
clock_t TTest_application::stop_progind()
|
|
{
|
|
clock_t t = clock();
|
|
if (_pi != NULL)
|
|
{
|
|
delete _pi;
|
|
_pi = NULL;
|
|
}
|
|
return t;
|
|
}
|
|
|
|
|
|
bool TTest_application::test1(TLog_report& log)
|
|
{
|
|
bool ok = true;
|
|
TLocalisamfile tab(LF_COMUNI);
|
|
|
|
TRecnotype r = 0;
|
|
TString80 msg;
|
|
|
|
const int times = 10;
|
|
const clock_t start = start_progind(times, TR("Lettura file comuni"));
|
|
for (int i = 0; i < times; i++)
|
|
{
|
|
for (tab.first(); tab.good(); tab.next())
|
|
r++;
|
|
|
|
msg.format(FR("%ld records %ld msec"), r, clock() - start);
|
|
|
|
_pi->set_text(msg);
|
|
if (!_pi->addstatus(1))
|
|
{
|
|
log.log(1, TR("Interrotto dall'utente"));
|
|
ok = false;
|
|
break;
|
|
}
|
|
}
|
|
|
|
const clock_t t = stop_progind() - start;
|
|
msg.format("Lettura file comuni - "
|
|
"%ld records in %ld msec - %lg records per sec", r, t, 1000.0*r/t);
|
|
log.log(0, msg);
|
|
return ok;
|
|
}
|
|
|
|
bool TTest_application::test2(TLog_report& log)
|
|
{
|
|
bool ok = true;
|
|
TRelation rel(LF_COMUNI);
|
|
TCursor tab(&rel);
|
|
|
|
const TRecnotype n = tab.items();
|
|
|
|
tab.freeze();
|
|
|
|
clock_t start;
|
|
TRecnotype r = 0;
|
|
TString80 msg;
|
|
{
|
|
const int times = 10;
|
|
TProgind p(times, TR("Lettura cursore comuni"), TRUE, TRUE);
|
|
start = start_timer();
|
|
for (int i = 0; i < times; i++)
|
|
{
|
|
for (tab = 0; tab.pos() < n; ++tab)
|
|
r++;
|
|
|
|
msg.format("Lettura cursore comuni\n%ld records %ld msec", r, clock() - start);
|
|
p.set_text(msg);
|
|
if (!p.addstatus(1))
|
|
{
|
|
log.log(1, TR("Interrotto dall'utente"));
|
|
ok = false;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
const clock_t t = clock() - start;
|
|
msg.format("Lettura cursore comuni: %ld records in %ld msec - %lg records per sec\n",
|
|
r, t, 1000.0*r/t);
|
|
log.log(0, msg);
|
|
return ok;
|
|
}
|
|
|
|
bool TTest_application::test3(TLog_report& log)
|
|
{
|
|
bool ok = true;
|
|
TRelation rel(LF_COMUNI);
|
|
TSorted_cursor tab(&rel, "CAPCOM|DENCOM");
|
|
|
|
clock_t istart = start_timer();
|
|
const TRecnotype n = tab.items();
|
|
clock_t istop = clock() - istart;
|
|
|
|
tab.freeze();
|
|
|
|
clock_t start;
|
|
TRecnotype r = 0;
|
|
TString256 msg;
|
|
{
|
|
const int times = 10;
|
|
TProgind p(times, TR("Lettura cursore C.A.P."), TRUE, TRUE);
|
|
start = start_timer();
|
|
for (int i = 0; i < times; i++)
|
|
{
|
|
for (tab = 0; tab.pos() < n; ++tab)
|
|
r++;
|
|
|
|
msg.format("Lettura cursore C.A.P.\n%ld records %ld msec", r, clock() - start);
|
|
p.set_text(msg);
|
|
if (!p.addstatus(1))
|
|
{
|
|
log.log(1, TR("Interrotto dall'utente"));
|
|
ok = false;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
const clock_t t = clock() - start;
|
|
msg.format("Lettura cursore ordinato %ld records in %ld msec - %lg records per sec - "
|
|
"%ld msec for initialization",
|
|
r, t, 1000.0*r/t, istop);
|
|
log.log(0, msg);
|
|
return ok;
|
|
}
|
|
|
|
bool TTest_application::test4(TLog_report& log)
|
|
{
|
|
bool ok = true;
|
|
long r = 0;
|
|
srand(r);
|
|
TString8 cod;
|
|
|
|
clock_t start;
|
|
{
|
|
const int times = 10;
|
|
TProgind p(times, TR("Lettura casuale tramite cache"), TRUE, TRUE);
|
|
cache().get(LF_COMUNI, cod); // Inizializzazione
|
|
start = start_timer();
|
|
for (int i = 0; i < times; i++)
|
|
{
|
|
if (!p.addstatus(1))
|
|
{
|
|
log.log(1, TR("Interrotto dall'utente"));
|
|
ok = false;
|
|
break;
|
|
}
|
|
for (long j = 0; j < 10000; j++)
|
|
{
|
|
const int rn = rand();
|
|
cod.format(" |%c%03d", 'A'+(rn%2), rn % 1000);
|
|
cache().get(LF_COMUNI, cod);
|
|
r++;
|
|
}
|
|
}
|
|
}
|
|
|
|
const clock_t t = clock() - start;
|
|
TString msg;
|
|
msg.format("Lettura casuale di %ld records in %ld msec - %lg records per sec",
|
|
r, t, 1000.0*r/t);
|
|
log.log(0, msg);
|
|
return ok;
|
|
}
|
|
|
|
bool TTest_application::test5(TLog_report& log)
|
|
{
|
|
bool ok = true;
|
|
long r = 0;
|
|
srand(r);
|
|
TString8 cod;
|
|
|
|
clock_t start;
|
|
{
|
|
const int times = 10;
|
|
TProgind p(times, TR("Lettura casuale senza cache"), TRUE, TRUE);
|
|
TLocalisamfile f(LF_COMUNI);
|
|
start = start_timer();
|
|
for (int i = 0; i < times; i++)
|
|
{
|
|
if (!p.addstatus(1))
|
|
{
|
|
log.log(1, TR("Interrotto dall'utente"));
|
|
ok = false;
|
|
break;
|
|
}
|
|
for (long j = 0; j < 10000; j++)
|
|
{
|
|
const int rn = rand();
|
|
cod.format("%c%03d", 'A'+(rn%2), rn % 1000);
|
|
f.put(COM_COM, cod);
|
|
f.read();
|
|
r++;
|
|
}
|
|
}
|
|
}
|
|
|
|
const clock_t t = clock() - start;
|
|
TString msg;
|
|
msg.format("Lettura casuale di %ld records in %ld msec - %lg records per sec",
|
|
r, t, 1000.0*r/t);
|
|
log.log(0, msg);
|
|
return ok;
|
|
}
|
|
|
|
bool TTest_application::test6(TLog_report& log)
|
|
{
|
|
bool ok = true;
|
|
TString msg;
|
|
TRecnotype n = 100;
|
|
|
|
if (n > 0)
|
|
{
|
|
TTable tab("CZZ");
|
|
msg.format("Creazione di %ld records", n);
|
|
const clock_t start = start_progind(n, msg);
|
|
int i;
|
|
for (i = 0; i < n; i++)
|
|
{
|
|
tab.put("CODTAB", i+1);
|
|
tab.write();
|
|
if (!_pi->addstatus(1))
|
|
{
|
|
log.log(1, TR("Interrotto dall'utente"));
|
|
ok = false;
|
|
break;
|
|
}
|
|
}
|
|
const clock_t t = stop_progind() - start;
|
|
msg.format("Scritti %ld records in %ld msec - %lg records per sec", i, t, 1000.0*i/t);
|
|
log.log(0, msg);
|
|
}
|
|
|
|
if (n > 0)
|
|
{
|
|
TRelation rel("CZZ");
|
|
TCursor cur(&rel);
|
|
n = cur.items();
|
|
cur.freeze();
|
|
|
|
msg.format("Cancellazione %ld records", n);
|
|
const clock_t start = start_progind(n, msg);
|
|
for (cur = 0; cur.pos() < n; ++cur)
|
|
{
|
|
cur.file().remove();
|
|
if (!_pi->addstatus(1))
|
|
{
|
|
log.log(1, TR("Interrotto dall'utente"));
|
|
ok = false;
|
|
break;
|
|
}
|
|
}
|
|
const clock_t t = stop_progind() - start;
|
|
msg.format("Cancellati %ld records in %ld msec - %lg records per sec", n, t, 1000.0*n/t);
|
|
log.log(0, msg);
|
|
}
|
|
return ok;
|
|
}
|
|
|
|
bool TTest_application::test7(TLog_report& log)
|
|
{
|
|
bool ok = true;
|
|
TString msg;
|
|
TRecnotype n = 10000;
|
|
|
|
if (n > 0)
|
|
{
|
|
TSystemisamfile tab(LF_TAB);
|
|
tab.open(_excllock);
|
|
msg.format("Creazione di %ld records", n);
|
|
const clock_t start = start_progind(n, msg);
|
|
int i;
|
|
for (i = 0; i < n; i++)
|
|
{
|
|
tab.curr().put("COD", "CZZ");
|
|
tab.curr().put("CODTAB", i+1);
|
|
tab.write();
|
|
if (!_pi->addstatus(1))
|
|
{
|
|
log.log(1, TR("Interrotto dall'utente"));
|
|
ok = false;
|
|
break;
|
|
}
|
|
}
|
|
const clock_t t = stop_progind() - start;
|
|
msg.format("Scritti %ld records in %ld msec - %lg records per sec", i, t, 1000.0*i/t);
|
|
log.log(0, msg);
|
|
tab.close();
|
|
}
|
|
|
|
if (n > 0)
|
|
{
|
|
TSystemisamfile tab(LF_TAB);
|
|
tab.open(_excllock);
|
|
|
|
TRelation rel("CZZ");
|
|
TCursor cur(&rel);
|
|
n = cur.items();
|
|
cur.freeze();
|
|
|
|
msg.format("Cancellazione %ld records", n);
|
|
const clock_t start = start_progind(n, msg);
|
|
for (cur = 0; cur.pos() < n; ++cur)
|
|
{
|
|
tab.put("COD", cur.curr().get("COD"));
|
|
tab.put("CODTAB", cur.curr().get("CODTAB"));
|
|
tab.remove();
|
|
if (!_pi->addstatus(1))
|
|
{
|
|
log.log(1, TR("Interrotto dall'utente"));
|
|
ok = false;
|
|
break;
|
|
}
|
|
}
|
|
const clock_t t = stop_progind() - start;
|
|
msg.format("Cancellati %ld records in %ld msec - %lg records per sec", n, t, 1000.0*n/t);
|
|
log.log(0, msg);
|
|
tab.close();
|
|
}
|
|
return ok;
|
|
}
|
|
|
|
bool TTest_application::test(int n, TLog_report& log)
|
|
{
|
|
bool ok = false;
|
|
switch (n)
|
|
{
|
|
case 1: ok = test1(log); break;
|
|
case 2: ok = test2(log); break;
|
|
case 3: ok = test3(log); break;
|
|
case 4: ok = test4(log); break;
|
|
case 5: ok = test5(log); break;
|
|
case 6: ok = test6(log); break;
|
|
case 7: ok = test7(log); break;
|
|
default: ok = false; break;
|
|
}
|
|
return ok;
|
|
}
|
|
|
|
|
|
void TTest_application::main_loop()
|
|
{
|
|
int te = -1;
|
|
int ti = 3;
|
|
|
|
for (int a = argc()-1; a > 1; a--)
|
|
{
|
|
const TFixed_string t(argv(a));
|
|
if (t.starts_with("test="))
|
|
te = atoi(t.mid(5)); else
|
|
if (t.starts_with("times="))
|
|
ti = atoi(t.mid(6));
|
|
}
|
|
|
|
const bool interactive = te < 0;
|
|
|
|
while (true)
|
|
{
|
|
if (interactive)
|
|
{
|
|
TProfiler_mask m;
|
|
m.set(101, te);
|
|
m.set(102, ti);
|
|
if (m.run() == K_QUIT)
|
|
break;
|
|
te = m.get_int(101);
|
|
ti = m.get_int(102);
|
|
if (ti <= 0)
|
|
ti = 1;
|
|
}
|
|
|
|
TLog_report log(TR("Report"));
|
|
|
|
bool ok = true;
|
|
for (int t = 1; ok && t <= 6; t++)
|
|
{
|
|
if (te <= 0 || te == t)
|
|
{
|
|
log.log(0, "");
|
|
for (int i = 0; ok && i < ti; i++)
|
|
ok = test(t, log);
|
|
}
|
|
}
|
|
|
|
if (interactive)
|
|
log.preview();
|
|
else
|
|
break;
|
|
}
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
int ba1200(int argc, char** argv)
|
|
{
|
|
TTest_application a;
|
|
a.run(argc, argv, TR("Performance profiler"));
|
|
return 0;
|
|
}
|
|
|