Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
main.cpp File Reference
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include "unit.h"
#include <time.h>
#include "collection.h"

Go to the source code of this file.

Macros

#define SIZE   60000
 

Functions

UnitcreateUnit ()
 
void Iteration (UnitCollection *c, int *levels2)
 
int main ()
 

Macro Definition Documentation

#define SIZE   60000

Definition at line 9 of file main.cpp.

Referenced by main().

Function Documentation

Unit* createUnit ( )

Definition at line 14 of file main.cpp.

Referenced by main().

15 {
16  return new Unit( false );
17 }
void Iteration ( UnitCollection c,
int levels2 
)

Definition at line 19 of file main.cpp.

References UnitCollection::createIterator(), and Unit::Kill().

Referenced by main().

20 {
21  Unit *unit = NULL;
22  ++(*levels2);
23  for (un_iter iter = c->createIterator(); unit = *iter;) {
24  int temp = rand();
25  if (temp < RAND_MAX/400) {
26  unit->Kill();
27  } else if (temp < RAND_MAX/102) {
28  iter.remove();
29  continue;
30  } else if (temp < RAND_MAX/90) {
31  Iteration( c, levels2 );
32  }
33  ++iter;
34  }
35 }
int main ( )

Definition at line 37 of file main.cpp.

References c, UnitCollection::createIterator(), createUnit(), UnitCollection::empty(), UnitCollection::FreeUnusedNodes(), i, Iteration(), Unit::Kill(), UnitCollection::UnitIterator::notDone(), UnitCollection::prepend(), rnd(), and SIZE.

38 {
39  Unit *unit;
40  srand( time( NULL ) );
42  Unit *u[SIZE];
43  time_t seconds;
44  for (int i = 0; i < SIZE; ++i)
45  u[i] = createUnit();
46  seconds = time( NULL );
47  for (int i = 0; i < (SIZE/2); ++i)
48  c->prepend( u[i] );
49  seconds = time( NULL )-seconds;
50  printf( "constructed list of size : %d in %d seconds using prepend\n", SIZE/2, seconds );
51  printf( "Randomnly inserting %d \n", SIZE/2 );
52  int ii = SIZE/2;
53  seconds = time( NULL );
54  while (ii < SIZE)
55  for (un_iter iter = c->createIterator(); iter.notDone() && ii < SIZE; ++iter) {
56  int rnd = rand();
57  if (rnd < RAND_MAX/200) {
58  iter.postinsert( u[ii] );
59  ++ii;
60  } else if (rnd < RAND_MAX/100) {
61  iter.preinsert( u[ii] );
62  ++ii;
63  }
64  }
65  seconds = time( NULL )-seconds;
66  printf( ".... took %d seconds \n", seconds );
67  for (int i = 0; i < SIZE/32; ++i)
68  if (rand() < RAND_MAX/20)
69  u[i]->Kill();
70  printf( "randomly killed SIZE/32 to start off with \n" );
71 
72  printf( "beginning unitCollection removal/advance operations\n" );
73  seconds = time( NULL );
74  int passes = 0;
75  int levels = 0;
76  while ( !c->empty() ) {
77  ++passes;
78  Iteration( c, &levels );
79 #if !oldtest
80  }
81 #else
83  }
85 #endif
86  seconds = time( NULL )-seconds;
87  printf( "operations took %d seconds \n", seconds );
88  levels = levels/passes;
89  printf( "Average number of concurrent iterators %d\n", levels );
90  printf( "verifying destruction of units\n" );
91  for (unsigned int i = 0; i < SIZE; i++) {
92  if (u[i]->zapped != u[i]->killed)
93  printf( "Unit at %d is zapped %d killed %d\n", i, u[i]->zapped, u[i]->killed );
94  else
95  delete u[i];
96  }
97  int size = 0;
98  for (un_iter counter = c->createIterator(); counter.notDone(); ++counter)
99  ++size;
100  printf( "size of list is verified at %d : %d killed \n", size, SIZE-size );
101  delete c;
102  printf( "completed\n" );
103  return 0;
104 }