#include #include #include #include /////////////////////////////////////////////////////////// // Testfil /////////////////////////////////////////////////////////// class TTest_application : public TSkeleton_application { protected: void test1(); void test2(); void test3(); clock_t start_timer() const; public: virtual void main_loop(); }; clock_t TTest_application::start_timer() const { clock_t t, s = clock(); do t = clock(); while (t == s); return t; } void TTest_application::test1() { TLocalisamfile tab(LF_COMUNI); const TRecnotype n = tab.items(); clock_t start; TRecnotype r = 0; TString80 msg; { const int times = 10; TProgind p(times, TR("Lettura file comuni"), TRUE, TRUE); start = start_timer(); for (int i = 0; i < times; i++) { for (tab.first(); tab.good(); tab.next()) r++; msg.format("%ld records %ld msec", r, clock() - start); p.addstatus(1); p.set_text(msg); if (p.iscancelled()) break; } } const clock_t t = clock() - start; msg.format("%ld records in %ld msec\n%lg records per sec", r, t, 1000.0*r/t); message_box(msg); } void TTest_application::test2() { 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("%ld records %ld msec", r, clock() - start); p.addstatus(1); p.set_text(msg); if (p.iscancelled()) break; } } const clock_t t = clock() - start; msg.format("%ld records in %ld msec\n%lg records per sec\n", r, t, 1000.0*r/t); message_box(msg); } void TTest_application::test3() { TRelation rel(LF_COMUNI); TSorted_cursor tab(&rel, "CAPCOM"); 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("%ld records %ld msec", r, clock() - start); p.addstatus(1); p.set_text(msg); if (p.iscancelled()) break; } } const clock_t t = clock() - start; msg.format("%ld records in %ld msec\n%lg records per sec\n" "%ld msec for initialization", r, t, 1000.0*r/t, istop); message_box(msg); } void TTest_application::main_loop() { test1(); test2(); test3(); } /////////////////////////////////////////////////////////// int ba1200(int argc, char** argv) { TTest_application a; a.run(argc, argv, TR("Test File")); return 0; }