[MOAB-dev] r2915 - MOAB/trunk/tools/iMesh/python/perf

jvporter at wisc.edu jvporter at wisc.edu
Wed May 27 16:47:12 CDT 2009


Author: jvporter
Date: 2009-05-27 16:47:11 -0500 (Wed, 27 May 2009)
New Revision: 2915

Modified:
   MOAB/trunk/tools/iMesh/python/perf/perf.c
   MOAB/trunk/tools/iMesh/python/perf/perf.py
Log:
Rework performance tests to be more flexible


Modified: MOAB/trunk/tools/iMesh/python/perf/perf.c
===================================================================
--- MOAB/trunk/tools/iMesh/python/perf/perf.c	2009-05-27 19:50:01 UTC (rev 2914)
+++ MOAB/trunk/tools/iMesh/python/perf/perf.c	2009-05-27 21:47:11 UTC (rev 2915)
@@ -1,4 +1,3 @@
-#include <dirent.h>
 #include <iMesh.h>
 #include <string.h>
 #include <stdio.h>
@@ -39,142 +38,123 @@
     return str;
 }
 
-int testable(const char *file)
-{
-    int len = strlen(file);
-    return (file[len-2] == '.' && file[len-1] == 'g') &&
-        strncmp(file,"testquad",8);
-}
-
 int main(int argc,char **argv)
 {
-    DIR *dir;
-    struct dirent *ent;
+    int count;
+    struct timeval start,end;
+    int err;
+    iMesh_Instance mesh=0;
+    iBase_EntitySetHandle root;
+    char *file;
+    int i;
 
-    if(argc != 2)
+    if(argc != 3)
     {
-        fprintf(stderr,"Usage: perf directory-name\n");
+        fprintf(stderr,"Usage: perf count file\n");
         return 1;
     }
 
-    dir = opendir(argv[1]);
-    if(dir == NULL)
+    count = atoi(argv[1]);
+    if(count == 0)
         return 1;
-    chdir(argv[1]);
+    file = argv[2];
 
-    while((ent = readdir(dir)) != NULL)
+    /***** 1 *****/
+    gettimeofday(&start,0);
+    for(i=0; i<count; i++)
     {
-        struct timeval start,end;
-        int err;
-        iMesh_Instance mesh=0;
-        iBase_EntitySetHandle root;
-        char *file = ent->d_name;
-        int i;
-
-        if(!testable(file))
-            continue;
-
-        printf("%s,",file);
-
-        /***** 1 *****/
-        gettimeofday(&start,0);
-        for(i=0; i<100; i++)
-        {
-            iMesh_Instance mesh;
-            iMesh_newMesh("",&mesh,&err,0);
-            iMesh_getRootSet(mesh,&root,&err);
-            iMesh_load(mesh,root,file,"",&err,strlen(file),0);
-            iMesh_dtor(mesh,&err);
-        }
-        gettimeofday(&end,0);
-        printf("%s,",format_delta(&end,&start));
-
+        iMesh_Instance mesh;
         iMesh_newMesh("",&mesh,&err,0);
         iMesh_getRootSet(mesh,&root,&err);
         iMesh_load(mesh,root,file,"",&err,strlen(file),0);
+        iMesh_dtor(mesh,&err);
+    }
+    gettimeofday(&end,0);
+    printf("%s\n",format_delta(&end,&start));
 
-        /***** 2 *****/
-        iBase_EntityHandle *entities=0;
-        int ent_size=0,ent_alloc;
-        iBase_EntityHandle *adj=0;
-        int adj_size=0,adj_alloc;
-        int *indices=0;
-        int ind_size=0,ind_alloc;
-        int *offsets=0;
-        int off_size=0,off_alloc;
+    iMesh_newMesh("",&mesh,&err,0);
+    iMesh_getRootSet(mesh,&root,&err);
+    iMesh_load(mesh,root,file,"",&err,strlen(file),0);
 
+    /***** 2 *****/
+    iBase_EntityHandle *entities=0;
+    int ent_size=0,ent_alloc;
+    iBase_EntityHandle *adj=0;
+    int adj_size=0,adj_alloc;
+    int *indices=0;
+    int ind_size=0,ind_alloc;
+    int *offsets=0;
+    int off_size=0,off_alloc;
+
+    gettimeofday(&start,0);
+    for(i=0; i<count; i++)
+    {
+        free(entities); entities = 0; ent_size = 0;
+        free(adj);      adj = 0;      adj_size = 0;
+        free(indices);  indices = 0;  ind_size = 0;
+        free(offsets);  offsets = 0;  off_size = 0;
+            
+        iMesh_getAdjEntIndices(mesh,root,iBase_ALL_TYPES,
+                               iMesh_ALL_TOPOLOGIES,iBase_ALL_TYPES,
+                               &entities,&ent_size,&ent_alloc,
+                               &adj,     &adj_size,&adj_alloc,
+                               &indices, &ind_size,&ind_alloc,
+                               &offsets, &off_size,&off_alloc,
+                               &err);
+    }
+    gettimeofday(&end,0);
+    printf("%s\n",format_delta(&end,&start));
+
+    /***** 3 *****/
+    {
+        iBase_EntityHandle *adj2=0;
+        int adj2_size=0,adj2_alloc;
+        int *offsets2=0;
+        int off2_size=0,off2_alloc;
+
         gettimeofday(&start,0);
-        for(i=0; i<100; i++)
+        for(i=0; i<count; i++)
         {
-            free(entities); entities = 0; ent_size = 0;
-            free(adj);      adj = 0;      adj_size = 0;
-            free(indices);  indices = 0;  ind_size = 0;
-            free(offsets);  offsets = 0;  off_size = 0;
-            
-            iMesh_getAdjEntIndices(mesh,root,iBase_ALL_TYPES,
-                                   iMesh_ALL_TOPOLOGIES,iBase_ALL_TYPES,
-                                   &entities,&ent_size,&ent_alloc,
-                                   &adj,     &adj_size,&adj_alloc,
-                                   &indices, &ind_size,&ind_alloc,
-                                   &offsets, &off_size,&off_alloc,
-                                   &err);
+            adj2 = 0;     adj2_size = 0;
+            offsets2 = 0; off2_size = 0;
+            iMesh_getEntArrAdj(mesh,entities,ent_size,iBase_ALL_TYPES,
+                               &adj2,&adj2_size,&adj2_alloc,
+                               &offsets2,&off2_size,&off2_alloc,&err);
+            free(adj2);
+            free(offsets2);
         }
         gettimeofday(&end,0);
-        printf("%s,",format_delta(&end,&start));
+        printf("%s\n",format_delta(&end,&start));
+    }
 
-        /***** 3 *****/
-        {
-            iBase_EntityHandle *adj2=0;
-            int adj2_size=0,adj2_alloc;
-            int *offsets2=0;
-            int off2_size=0,off2_alloc;
+    /***** 4 *****/
+    {
+        iBase_EntityHandle *adj2=0;
+        int adj2_size=0,adj2_alloc;
+        int *offsets2=0;
+        int off2_size=0,off2_alloc;
 
-            gettimeofday(&start,0);
-            for(i=0; i<100; i++)
-            {
-                adj2 = 0;     adj2_size = 0;
-                offsets2 = 0; off2_size = 0;
-                iMesh_getEntArrAdj(mesh,entities,ent_size,iBase_ALL_TYPES,
-                                   &adj2,&adj2_size,&adj2_alloc,
-                                   &offsets2,&off2_size,&off2_alloc,&err);
-                free(adj2);
-                free(offsets2);
-            }
-            gettimeofday(&end,0);
-            printf("%s,",format_delta(&end,&start));
-        }
-
-        /***** 4 *****/
+        gettimeofday(&start,0);
+        for(i=0; i<count; i++)
         {
-            iBase_EntityHandle *adj2=0;
-            int adj2_size=0,adj2_alloc;
-            int *offsets2=0;
-            int off2_size=0,off2_alloc;
-
-            gettimeofday(&start,0);
-            for(i=0; i<100; i++)
-            {
-                adj2 = 0;     adj2_size = 0;
-                offsets2 = 0; off2_size = 0;
-                iMesh_getEntArr2ndAdj(mesh,entities,ent_size,
-                                      iBase_EDGE,iBase_VERTEX,
-                                      &adj2,&adj2_size,&adj2_alloc,
-                                      &offsets2,&off2_size,&off2_alloc,&err);
-                free(adj2);
-                free(offsets2);
-            }
-            gettimeofday(&end,0);
-            printf("%s\n",format_delta(&end,&start));
+            adj2 = 0;     adj2_size = 0;
+            offsets2 = 0; off2_size = 0;
+            iMesh_getEntArr2ndAdj(mesh,entities,ent_size,
+                                  iBase_EDGE,iBase_VERTEX,
+                                  &adj2,&adj2_size,&adj2_alloc,
+                                  &offsets2,&off2_size,&off2_alloc,&err);
+            free(adj2);
+            free(offsets2);
         }
-
-        free(entities);
-        free(adj);
-        free(indices);
-        free(offsets);
-        iMesh_dtor(mesh,&err);
+        gettimeofday(&end,0);
+        printf("%s\n",format_delta(&end,&start));
     }
 
-    closedir(dir);
+    free(entities);
+    free(adj);
+    free(indices);
+    free(offsets);
+    iMesh_dtor(mesh,&err);
 
     return 0;
 }

Modified: MOAB/trunk/tools/iMesh/python/perf/perf.py
===================================================================
--- MOAB/trunk/tools/iMesh/python/perf/perf.py	2009-05-27 19:50:01 UTC (rev 2914)
+++ MOAB/trunk/tools/iMesh/python/perf/perf.py	2009-05-27 21:47:11 UTC (rev 2915)
@@ -1,10 +1,9 @@
 import re
 import os
-import sys
 import subprocess
-import csv
 from datetime import *
 from itaps import *
+from optparse import OptionParser
 
 class stopwatch:
     def __init__(self):
@@ -22,36 +21,56 @@
         not re.match('testquad',name)
 
 
-c_stats  = {}
-py_stats = {}
+##### Parse command line options #####
+parser = OptionParser(usage='usage: %prog [options] [files...]')
+parser.add_option('-c', '--count', action='store', type='int', default=20,
+                  help='number of times to run the performance tests',
+                  metavar='NUM')
+
+(options, args) = parser.parse_args()
+
+if len(args) == 0:
+    args = ['.']
+
+files = []
+for path in args:
+    if os.path.isdir(path):
+        files.extend([ os.path.join(path,i) for i in 
+                       filter(testable, os.listdir(path)) ])
+    else:
+        files.append(path)
+
+count = options.count
+
+
+c_stats    = {}
+py_stats   = {}
 list_stats = {}
 
-path = raw_input('Location of test files: ')
-if(len(path) == 0):
-    path = '.'
-
 ##### Run some tests in C #####
-lines = csv.reader( subprocess.Popen('./perf %s' % path, shell=True,
-                                     stdout=subprocess.PIPE).stdout )
-for row in lines:
-    c_stats[row[0]] = [float(i)/100 for i in row[1:]]
+for file in files:
+    results = subprocess.Popen('./perf %d "%s"' % (count, file), shell=True,
+                               stdout=subprocess.PIPE).stdout
+    c_stats[file] = [float(line)/count for line in results]
 
-
 ##### Run some tests in Python #####
-os.chdir(path)
 timer = stopwatch()
 
-for file in filter(testable, os.listdir(path)):
+for file in files:
     py_stats[file] = []
     list_stats[file] = []
 
     ##### 1 #####
     timer.reset()
-    for x in range(100):
+    for x in range(count):
         m = iMesh()
-        m.load(m.rootSet, file)
+        try:
+            m.load(m.rootSet, file)
+        except:
+            print file
+            exit(0)
         m = None
-    py_stats[file].append( timer.delta()/100 )
+    py_stats[file].append( timer.delta()/count )
     list_stats[file].append(0)
 
     ##### Intermission #####
@@ -61,10 +80,10 @@
 
     ##### 2 #####
     timer.reset()
-    for x in range(100):
+    for x in range(count):
         mesh.getAdjEntIndices(root, iBase.type.all,
                               iMesh.topology.all, iBase.type.all)
-    py_stats[file].append( timer.delta()/100 )
+    py_stats[file].append( timer.delta()/count )
     list_stats[file].append(0)
 
     ##### Intermission #####
@@ -74,25 +93,25 @@
 
     ##### 3 #####
     timer.reset()
-    for x in range(100):
+    for x in range(count):
         mesh.getEntAdj(arr[0], iBase.type.all)
-    py_stats[file].append( timer.delta()/100 )
+    py_stats[file].append( timer.delta()/count )
 
     timer.reset()
-    for x in range(100):
+    for x in range(count):
         mesh.getEntAdj(list[0], iBase.type.all)
-    list_stats[file].append( timer.delta()/100 )
+    list_stats[file].append( timer.delta()/count )
 
     ##### 4 #####
     timer.reset()
-    for x in range(100):
+    for x in range(count):
         mesh.getEnt2ndAdj(arr[0], iBase.type.edge, iBase.type.vertex)
-    py_stats[file].append( timer.delta()/100 )
+    py_stats[file].append( timer.delta()/count )
 
     timer.reset()
-    for x in range(100):
+    for x in range(count):
         mesh.getEnt2ndAdj(list[0], iBase.type.edge, iBase.type.vertex)
-    list_stats[file].append( timer.delta()/100 )
+    list_stats[file].append( timer.delta()/count )
 
     mesh = None
     arr = None
@@ -104,7 +123,7 @@
 import numpy
 
 i = 1
-for file in filter(testable, os.listdir(path)):
+for file in files:
     ind = numpy.arange(len(py_stats[file]))
     width = 0.25
     plt.figure(i)



More information about the moab-dev mailing list