[pypy-svn] r60542 - pypy/extradoc/talk/ecoop2009/benchmarks

fijal at codespeak.net fijal at codespeak.net
Wed Dec 17 15:39:34 CET 2008


Author: fijal
Date: Wed Dec 17 15:39:32 2008
New Revision: 60542

Added:
   pypy/extradoc/talk/ecoop2009/benchmarks/accumulator.cpp
Log:
incomplete c++ solution for accumulator benchmark


Added: pypy/extradoc/talk/ecoop2009/benchmarks/accumulator.cpp
==============================================================================
--- (empty file)
+++ pypy/extradoc/talk/ecoop2009/benchmarks/accumulator.cpp	Wed Dec 17 15:39:32 2008
@@ -0,0 +1,73 @@
+
+#include <stdlib.h>
+#include <iostream>
+
+class Accumulator
+{
+ public:
+  virtual void accumulate(int x);
+  virtual int getvalue();
+};
+
+class Add : public Accumulator
+{
+  int value;
+public:
+  Add()
+  {
+    value = 0;
+  }
+
+  void accumulate(int x)
+  {
+    value += x;
+  }
+  int getvalue()
+  {
+    return value;
+  }
+};
+
+class Count : public Accumulator
+{
+  int value;
+public:
+  Count()
+  {
+    value = 0;
+  }
+  void accumulate(int x)
+  {
+    value++;
+  }
+  int getvalue()
+  {
+    return value;
+  }
+};
+
+int accumulator(int n)
+{
+  Accumulator* acc = NULL;
+  int res;
+
+  if (n < 0) {
+    n = -n;
+    acc = new Count();
+  } else {
+    acc = new Add();
+  }
+  while (n-- > 0) {
+    acc->accumulate(n);
+  }
+  res = acc->getvalue();
+  delete acc;
+  return res;
+}
+
+
+int main(int argc, char **argv)
+{
+  int arg;
+  arg = atoi(argv[1]);
+}



More information about the Pypy-commit mailing list