Commits

Anonymous committed 95317db

added empty.{c, py} and bm_empty.py

Comments (0)

Files changed (4)

+from empty import Empty
+
+STORE_INSTANCE = {}
+STORE_FUNC = {}
+
+
+def _get_INSTANCE(key):
+    if key in STORE_INSTANCE:
+        return STORE_INSTANCE[key]
+    else:
+        inst = Empty(key[0])
+        STORE_INSTANCE[key] = inst
+        return inst
+
+
+def setup_benchmark(num_i=100, ido=0, ct=False):
+    key = (num_i, ido, ct)
+    if ct:
+        STORE_FUNC[key] = getattr(_get_INSTANCE(key), 'ctdonothing%d' % ido)
+    else:
+        STORE_FUNC[key] = getattr(_get_INSTANCE(key), 'donothing%d' % ido)
+
+
+def donothing(num_i=100, ido=0, ct=False):
+    STORE_FUNC[(num_i, ido, ct)]()
+from cexputils import MySimObject
+
+
+class Empty(MySimObject):
+
+    _clibname_ = 'libempty.so'
+    _cmembers_ = ['num_i', 'double dummy[i][i]']
+    _cfuncs_ = ['donothing0()',
+                'donothing1(int i=0)',
+                'donothing2(int i=0, int j=0)']
+
+    def __init__(self, num_i=100):
+        MySimObject.__init__(self, num_i=num_i)
+        self.__cfunc_ctdonothing0 = self._cfunc_loaded_['donothing0']
+        self.__cfunc_ctdonothing1 = self._cfunc_loaded_['donothing1']
+        self.__cfunc_ctdonothing2 = self._cfunc_loaded_['donothing2']
+
+    def ctdonothing0(self):
+        return self.__cfunc_ctdonothing0(self._struct_p_)
+
+    def ctdonothing1(self):
+        return self.__cfunc_ctdonothing1(self._struct_p_, 0)
+
+    def ctdonothing2(self):
+        return self.__cfunc_ctdonothing2(self._struct_p_, 0, 0)
+
+
+if __name__ == '__main__':
+    et = Empty()
+    for i in range(3):
+        getattr(et, 'donothing%d' % i)()
+        getattr(et, 'ctdonothing%d' % i)()

cexp/ext/src/empty.c

+typedef struct empty_{
+  int num_i;
+  double **dummy;
+} Empty;
+
+
+int Empty_donothing0(Empty *self)
+{
+  return 0;
+}
+
+
+int Empty_donothing1(Empty *self, int i)
+{
+  return 0;
+}
+
+
+int Empty_donothing2(Empty *self, int i, int j)
+{
+  return 0;
+}
             )
 
     cflags = ['-Wall', '-std=c99']
-    for trg in ['constinloop', 'userestrict']:
+    for trg in ['constinloop', 'userestrict', 'empty']:
         gene_bld(trg, trg, cflags)
         ## for optz in ['1', '2', '3']:
         ##     gene_bld(trg, '%s-O%s' % (trg, optz), cflags + ['-O%s' % optz])