Beispiel #1
0
int main(int argc, const char *argv[])
{
	int ret = 0;
	KonohaContext* konoha = CreateContext();
	test_gc(konoha);
	DeleteContext(konoha);
	assert(__Free__ == __Init__);
	fprintf(stderr, "alloced_object_count = %d, freed_object_count=%d\n", __Init__, __Free__);
	test_bitops();
	return ret;
}
int 
main(int argc, char *argv[])
{
   unsigned int i;
   bitfield *b1, *b2;

#ifdef MALLINFO
   struct mallinfo meminfo;
#endif

   long clk_tck = 0;
   const char * header_format = "%5s %8s %8s %8s %8s %8s %8s %8s %8s %8s %8s\n";
   const char * data_format   = "%5d %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f"
                                " %8.3f %8.3f %8d\n";

   /* evaluate commandline args */
   if (argc > 1) {
      test_bf_loops = atoi(argv[1]);
   }

   /* create array to hold bitfields, to be used per test loop */
   b1 = (bitfield *)malloc(test_bf_loops * sizeof (bitfield));
   b2 = (bitfield *)malloc(test_bf_loops * sizeof (bitfield));
   printf("performing %d loops per action\n", test_bf_loops);

   /* test nullpointer actions */
   printf("\ntesting nullpointer actions\n");
   test_nullpointer_actions();

   printf("\ntesting bit operations\n");
   test_bitops();

   /* test performance */
   clk_tck = sysconf(_SC_CLK_TCK); /* JG: TODO: sge_sysconf? */
   printf("\ntesting performance of all actions\n");
   printf(header_format, "size", "create", "free",
          "copy", "bwcopy",
          "set", "get",
          "clear", "reset", "changed", "mem");

   for (i = 0; i <= test_bf_max_size; i += 10) {
      struct tms tms_buffer;
      clock_t now, start;
      double prof_create = 0.0;
      double prof_free = 0.0;
      double prof_copy = 0.0;
      double prof_bwcopy = 0.0;
      double prof_set = 0.0;
      double prof_get = 0.0;
      double prof_clear = 0.0;
      double prof_reset = 0.0;
      double prof_changed = 0.0;

      unsigned int loops, index;

      srand(time(0));

      /* creation of bitfields */
      start = times(&tms_buffer);
      for (loops = 0; loops < test_bf_loops; loops++) {
         sge_bitfield_init(&b1[loops], i);
         sge_bitfield_init(&b2[loops], i);
      }
      now = times(&tms_buffer);
      prof_create = (now - start) * 1.0 / clk_tck;

      /* copy */
      start = times(&tms_buffer);
      for (loops = 0; loops < test_bf_loops; loops++) {
         sge_bitfield_copy(&b1[loops], &b2[loops]);
      }
      now = times(&tms_buffer);
      prof_copy = (now - start) * 1.0 / clk_tck;

      /* bitwise copy */
      start = times(&tms_buffer);
      for (loops = 0; loops < test_bf_loops; loops++) {
         sge_bitfield_bitwise_copy(&b2[loops], &b2[loops]);
      }
      now = times(&tms_buffer);
      prof_bwcopy = (now - start) * 1.0 / clk_tck;

      /* set/get/clear */
      index = rand() % (i + 1) - 1;
      start = times(&tms_buffer);
      for (loops = 0; loops < test_bf_loops; loops++) {
         sge_bitfield_set(&b1[loops], index);
      }
      now = times(&tms_buffer);
      prof_set = (now - start) * 1.0 / clk_tck;

      index = rand() % (i + 1) - 1;
      start = times(&tms_buffer);
      for (loops = 0; loops < test_bf_loops; loops++) {
         sge_bitfield_get(&b1[loops], index);
      }
      now = times(&tms_buffer);
      prof_get = (now - start) * 1.0 / clk_tck;

      index = rand() % (i + 1) - 1;
      start = times(&tms_buffer);
      for (loops = 0; loops < test_bf_loops; loops++) {
         sge_bitfield_clear(&b1[loops], index);
      }
      now = times(&tms_buffer);
      prof_clear = (now - start) * 1.0 / clk_tck;

      /* reset */
      start = times(&tms_buffer);
      for (loops = 0; loops < test_bf_loops; loops++) {
         sge_bitfield_reset(&b1[loops]);
      }
      now = times(&tms_buffer);
      prof_reset = (now - start) * 1.0 / clk_tck;

      /* changed */
      start = times(&tms_buffer);
      for (loops = 0; loops < test_bf_loops; loops++) {
         sge_bitfield_changed(&b1[loops]);
      }
      now = times(&tms_buffer);
      prof_changed = (now - start) * 1.0 / clk_tck;

      /* evaluate memory usage */
#ifdef MALLINFO
      meminfo = mallinfo();
#endif

      /* freeing of bitfields */
      start = times(&tms_buffer);
      for (loops = 0; loops < test_bf_loops; loops++) {
         sge_bitfield_free_data(&b1[loops]);
         sge_bitfield_free_data(&b2[loops]);
      }
      now = times(&tms_buffer);
      prof_free = (now - start) * 1.0 / clk_tck;

      printf(data_format, i, prof_create, prof_free,
             prof_copy, prof_bwcopy,
             prof_set, prof_get, prof_clear,
             prof_reset, prof_changed,
#ifdef MALLINFO
             (meminfo.usmblks + meminfo.uordblks) / 1024
#else
             0
#endif
            );
   }

   /* free memory used for bitfields */
   free(b1);
   free(b2);
   return EXIT_SUCCESS;
}