home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 3 / RISC_DISC_3.iso / resources / etexts / gems / gemsv / ch4_5 / timing.c < prev   
Encoding:
C/C++ Source or Header  |  1994-11-22  |  5.5 KB  |  186 lines

  1. /*
  2. // timing.c
  3. //
  4. //
  5. // Performance test of the sugguested ellipsoid generation method.
  6. // The fastest execution time among 100 runs of ellipsoid generation method
  7. // subtracted by the fastest execution time among 100 runs of gettimeofday
  8. // system call is output.
  9. //
  10. // A comparison is made to the IRIS GL sphere library.
  11. //
  12. // Here, depth denote the degree of subdivision.
  13. */
  14.  
  15. #include "ellipsoid.h"
  16.  
  17. #include <gl/gl.h>
  18. #include <gl/sphere.h>
  19.  
  20. #include <stdio.h>
  21. #include <sys/time.h>
  22. struct timeval t0, t1;
  23. long microsec;
  24.  
  25. #define max_depth 105
  26. #define max_run   100
  27.  
  28. struct {
  29.     long init;
  30.     long seq;
  31.     long par;
  32.     long libsphere;
  33. } timing[max_depth];
  34.  
  35. int main ()
  36. {
  37.     object ellipsoid;
  38.     int depth;
  39.     int run;
  40.  
  41.     long min_syscall = -1;
  42.     long min_init = -1;
  43.     long min_seq = -1;
  44.     long min_par = -1;
  45.     long min_libsphere_draw = -1;
  46.     long min_libsphere = -1;
  47.  
  48.     /*
  49.     // Find the fastest execution time among 100 runs
  50.     // of gettimeofday system call.
  51.     */
  52.     for (run = 1; run <= max_run; run++) {
  53.         gettimeofday (&t0);
  54.         gettimeofday (&t1);
  55.  
  56.         microsec = (t1.tv_sec-t0.tv_sec)*1000000 + (t1.tv_usec-t0.tv_usec);
  57.         if (min_syscall > microsec || min_syscall < 0)
  58.             min_syscall = microsec;
  59.     }
  60.  
  61.     /*
  62.     // Find the fastest execution time among 100 runs
  63.     // of ellipsoid initialization for each depth.
  64.     */
  65.     for (depth = 1; depth <= max_depth; depth++) {
  66.         for (run = 1; run <= max_run; run++) {
  67.             gettimeofday (&t0);
  68.             ellipsoid_init (depth);
  69.             gettimeofday (&t1);
  70.             ellipsoid_done ();
  71.  
  72.             microsec = (t1.tv_sec-t0.tv_sec)*1000000 + (t1.tv_usec-t0.tv_usec);
  73.             if (min_init > microsec || min_init < 0)
  74.                 min_init = microsec;
  75.         }
  76.         min_init -= min_syscall;
  77.         timing[depth-1].init = min_init;
  78.         min_init = -1;
  79.     }
  80.  
  81.     /*
  82.     // Find the fastest execution time among 100 runs
  83.     // of ellipsoid generation by ellipsoid_seq() for each depth.
  84.     */
  85.     ellipsoid_init (max_depth);
  86.     for (depth = 1; depth <= max_depth; depth++) {
  87.         for (run = 1; run <= max_run; run++) {
  88.             gettimeofday (&t0);
  89.             ellipsoid_seq (&ellipsoid, depth, 1.0, 2.0, 3.0);
  90.             gettimeofday (&t1);
  91.             ellipsoid_free (&ellipsoid);
  92.  
  93.             microsec = (t1.tv_sec-t0.tv_sec)*1000000 + (t1.tv_usec-t0.tv_usec);
  94.             if (min_seq > microsec || min_seq < 0)
  95.                 min_seq = microsec;
  96.         }
  97.         min_seq -= min_syscall;
  98.         timing[depth-1].seq = min_seq;
  99.         min_seq = -1;
  100.     }
  101.  
  102.     /*
  103.     // Find the fastest execution time among 100 runs
  104.     // of ellipsoid generation by ellipsoid_par() for each depth.
  105.     */
  106.     ellipsoid_init (max_depth);
  107.     for (depth = 1; depth <= max_depth; depth++) {
  108.         for (run = 1; run <= max_run; run++) {
  109.             gettimeofday (&t0);
  110.             ellipsoid_par (&ellipsoid, depth, 1.0, 2.0, 3.0);
  111.             gettimeofday (&t1);
  112.             ellipsoid_free (&ellipsoid);
  113.  
  114.             microsec = (t1.tv_sec-t0.tv_sec)*1000000 + (t1.tv_usec-t0.tv_usec);
  115.             if (min_par > microsec || min_par < 0)
  116.                 min_par = microsec;
  117.         }
  118.         min_par -= min_syscall;
  119.         timing[depth-1].par = min_par;
  120.         min_par = -1;
  121.     }
  122.  
  123.     /*
  124.     // Find the fastest execution time among 100 runs
  125.     // of sphere generation by IRIS GL sphere library for each depth.
  126.     */
  127.     foreground ();
  128.     noport ();
  129.     winopen ("");
  130.     sphmode (SPH_TESS, SPH_OCT); /* octahedral subdivision */
  131.     sphmode (SPH_PRIM, SPH_POLY);
  132.     for (depth = 1; depth <= SPH_MAXDEPTH; depth++) {
  133.         static float sphparams[] = { 0.0, 0.0, 0.0, 1.0 };
  134.  
  135.         /*
  136.         // Find the fastest execution time among 100 runs
  137.         // of sphere drawing by IRIS GL sphere library.
  138.         */
  139.         sphmode (SPH_DEPTH, depth);
  140.         sphdraw (sphparams); /* generation and drawing of the sphere */
  141.         for (run = 1; run <= max_run; run++) {
  142.             finish (); /* block until the geometry pipeline is empty */
  143.             gettimeofday (&t0);
  144.             sphdraw (sphparams); /* drawing only without generation */
  145.             gettimeofday (&t1);
  146.  
  147.             microsec = (t1.tv_sec-t0.tv_sec)*1000000 + (t1.tv_usec-t0.tv_usec);
  148.             if (min_libsphere_draw > microsec || min_libsphere_draw < 0)
  149.                 min_libsphere_draw = microsec;
  150.         }
  151.         sphfree ();
  152.         min_libsphere_draw -= min_syscall;
  153.  
  154.         /*
  155.         // Find the fastest execution time among 100 runs
  156.         // of sphere generation by IRIS GL sphere library.
  157.         */
  158.         for (run = 1; run <= max_run; run++) {
  159.             sphmode (SPH_DEPTH, depth);
  160.             finish ();
  161.             gettimeofday (&t0);
  162.             sphdraw (sphparams); /* generation and drawing of the sphere */
  163.             gettimeofday (&t1);
  164.             sphfree ();
  165.  
  166.             microsec = (t1.tv_sec-t0.tv_sec)*1000000 + (t1.tv_usec-t0.tv_usec);
  167.             if (min_libsphere > microsec || min_libsphere < 0)
  168.                 min_libsphere = microsec;
  169.         }
  170.         min_libsphere -= min_libsphere_draw + min_syscall;
  171.         timing[depth-1].libsphere = min_libsphere;
  172.         min_libsphere = -1;
  173.     }
  174.  
  175.     for (depth = 1; depth <= max_depth; depth++) {
  176.         printf ("depth = %3d: nv = %8d, nf = %8d, init = %8d, seq = %8d, par = %8d",
  177.             depth, 4*depth*depth + 2, 8*depth*depth,
  178.             timing[depth-1].init, timing[depth-1].seq, timing[depth-1].par);
  179.         if (depth <= SPH_MAXDEPTH)
  180.             printf (", libsphere = %8d", timing[depth-1].libsphere);
  181.         printf ("\n");
  182.     }
  183.  
  184.     return 0;
  185. }
  186.