https://svn.lrde.epita.fr/svn/genericity-support-comparison/trunk
2.0/src/oo/python/oo_python.py | 99 +++++++++++++++++++++++++++++++++++++++++ 2.0/src/st/ocaml/st_ocaml.ml | 4 - ChangeLog | 7 ++ 3 files changed, 108 insertions(+), 2 deletions(-)
Index: ChangeLog from Roland Levillain roland@lrde.epita.fr
Add a (simple) Python version.
* 2.0/src/oo/python/oo_python.py: New. * 2.0/src/st/ocaml/st_ocaml.ml: Fix comment.
Property changes on: 2.0/src/st/c++ ___________________________________________________________________ Name: svn:ignore + st_cpp_scoop_1 st_cpp_scoop_1i st_cpp_stl
Index: 2.0/src/st/ocaml/st_ocaml.ml --- 2.0/src/st/ocaml/st_ocaml.ml (revision 54) +++ 2.0/src/st/ocaml/st_ocaml.ml (revision 55) @@ -1,10 +1,10 @@ (* Compile with :
- ocamlc -o oo_ocaml unix.cma st_ocaml.ml + ocamlc -o st_ocaml unix.cma st_ocaml.ml
or :
- ocamlopt -o oo_ocaml.opt unix.cmxa st_ocaml.ml + ocamlopt -o st_ocaml.opt unix.cmxa st_ocaml.ml
*)
Property changes on: 2.0/src/st/ocaml ___________________________________________________________________ Name: svn:ignore + st_ocaml st_ocaml.opt st_ocaml.cmx st_ocaml.cmi st_ocaml.cmo
Property changes on: 2.0/src/dd/c ___________________________________________________________________ Name: svn:ignore + dd_c dd_ci
Index: 2.0/src/oo/python/oo_python.py --- 2.0/src/oo/python/oo_python.py (revision 0) +++ 2.0/src/oo/python/oo_python.py (revision 55) @@ -0,0 +1,99 @@ +#! /usr/bin/env python + +import sys, time +# Use Numerical Python for efficient arrays. +# http://numpy.sourceforge.net/numdoc/HTML/numdoc.htm +import Numeric + +# We don't use abstract classes here, since Python doesn't support +# this concept actually. + +# Value. +class Int: + def __init__ (self, value): + self.value = value + def assign (self, rhs): + self.value = rhs.value + def __add__ (self, rhs): + return self.value + rhs + def __str__ (self): + return "Int(" + str (self.value) + ")" + +# Point. +class Point1d: + def __init__ (self, i): + assert (i >= 0) + self.i = i + def dummy (self): + sys.stdout.write ("!") + def get_index (self): + return self.i + def set_index (self, i): + assert (i >= 0) + self.i = i + +# Piter. +class Piter1d: + def __init__ (self, n): + assert n >= 0 + self.n = n + self.p = Point1d (0) + def start (self): + self.p.set_index (0) + def next (self): + self.p.set_index (self.p.get_index () + 1) + def is_valid (self): + return self.p.get_index () < self.n + def point (self): + return self.p + +# Image. +class Image1d: + def __init__ (self, n, v): + assert n >= 0 + self.n = n + self.data = Numeric.zeros (n, Numeric.PyObject) + self.data[:] = v + def get (self, p): + return self.data[p.get_index ()] + def new_piter (self): + return Piter1d (self.n) + def __str__ (self): + return str (self.data) + + +# Pixel assignment. +def assign (ima, val): + p = ima.new_piter () + while p.is_valid (): + ima.get (p.point ()).assign (val) + p.next () + +def usage (program_name): + if not program_name: + program_name = "oo_python" + print "usage: " + program_name + " [size = 800] [nsteps = 200]" + sys.exit (1) + +# Driver. +if len (sys.argv) > 3: + usage (sys.argv[0]) +# Default values. +size = 800 +nsteps = 200; +if len (sys.argv) > 1: + size = int (sys.argv[1]) +if len (sys.argv) > 2: + nsteps = int (sys.argv[2]) +print "Linear / " + str (size) + "x" + str (size) + " / " + \ + str (nsteps) + " steps" +v = Int (0) +ima = Image1d (size, v) +val = Int (51) +# This expression is too complex to be handled by timeit.Timer. +# Anyway, time.clock() suffices here. +t0 = time.clock () +for i in range (nsteps): + assign (ima, val) +t1 = time.clock () +print t1 - t0
Property changes on: 2.0/src/oo/python/oo_python.py ___________________________________________________________________ Name: svn:executable + *
Property changes on: 2.0/src/oo/c++ ___________________________________________________________________ Name: svn:ignore + oo_cpp
Property changes on: 2.0/src/oo/ocaml ___________________________________________________________________ Name: svn:ignore + oo_ocaml oo_ocaml.opt oo_ocaml.cmi oo_ocaml.cmo oo_ocaml.cmx