184 lines
		
	
	
		
			3.9 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			184 lines
		
	
	
		
			3.9 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <time.h>
 | 
						|
 | 
						|
#include <applicat.h>
 | 
						|
#include <progind.h>
 | 
						|
#include <recarray.h>
 | 
						|
#include <relation.h>
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// Testfile
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
class TTest_application : public TSkeleton_application
 | 
						|
{
 | 
						|
protected:
 | 
						|
  void test1();
 | 
						|
  void test2();
 | 
						|
  void test3();
 | 
						|
  void test4();
 | 
						|
 | 
						|
  clock_t start_timer() const;
 | 
						|
 | 
						|
public:
 | 
						|
  virtual void main_loop();
 | 
						|
};
 | 
						|
 | 
						|
clock_t TTest_application::start_timer() const
 | 
						|
{
 | 
						|
  clock_t t = clock();
 | 
						|
  while (clock() == t);
 | 
						|
  t = clock();
 | 
						|
  return t;
 | 
						|
}
 | 
						|
 | 
						|
void TTest_application::test1()
 | 
						|
{            
 | 
						|
  TLocalisamfile tab(LF_COMUNI);
 | 
						|
  
 | 
						|
  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("Lettura file comuni\n"
 | 
						|
             "%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("Lettura cursore comuni\n%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|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.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::test4()
 | 
						|
{            
 | 
						|
  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++)
 | 
						|
    {
 | 
						|
      for (long j = 0; j < 10000; j++)
 | 
						|
      {
 | 
						|
        cod.format(" |%c%03d", 'A'+rand()%8, rand() % 1000);
 | 
						|
        cache().get(LF_COMUNI, cod);
 | 
						|
        r++;
 | 
						|
      }
 | 
						|
	    p.addstatus(1);
 | 
						|
		  if (p.iscancelled()) 
 | 
						|
        break;
 | 
						|
    }
 | 
						|
	}
 | 
						|
 | 
						|
	const clock_t t = clock() - start;
 | 
						|
  TString msg;
 | 
						|
	msg.format("%ld records in %ld msec\n%lg records per sec", r, t, 1000.0*r/t);             
 | 
						|
	message_box(msg);
 | 
						|
}
 | 
						|
 | 
						|
void TTest_application::main_loop()
 | 
						|
{
 | 
						|
  test1();
 | 
						|
  test2();
 | 
						|
  test3();
 | 
						|
  test4();
 | 
						|
}
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
 | 
						|
int ba1200(int argc, char** argv)
 | 
						|
{
 | 
						|
  TTest_application a;
 | 
						|
  a.run(argc, argv, TR("Test File"));
 | 
						|
  return 0;
 | 
						|
}
 | 
						|
 |