Commit 46a9d0fe authored by Stefan Behnel's avatar Stefan Behnel

convert benchmark to Py3

parent ce7ad25e
...@@ -18,7 +18,7 @@ __contact__ = "collinwinter@google.com (Collin Winter)" ...@@ -18,7 +18,7 @@ __contact__ = "collinwinter@google.com (Collin Winter)"
# Python imports # Python imports
import optparse import optparse
import sys import sys
import time from time import time
# Local imports # Local imports
import util import util
...@@ -26,7 +26,7 @@ import util ...@@ -26,7 +26,7 @@ import util
def combinations(l): def combinations(l):
"""Pure-Python implementation of itertools.combinations(l, 2).""" """Pure-Python implementation of itertools.combinations(l, 2)."""
result = [] result = []
for x in xrange(len(l) - 1): for x in range(len(l) - 1):
ls = l[x+1:] ls = l[x+1:]
for y in ls: for y in ls:
result.append((l[x],y)) result.append((l[x],y))
...@@ -78,7 +78,7 @@ PAIRS = combinations(SYSTEM) ...@@ -78,7 +78,7 @@ PAIRS = combinations(SYSTEM)
def advance(dt, n, bodies=SYSTEM, pairs=PAIRS): def advance(dt, n, bodies=SYSTEM, pairs=PAIRS):
for i in xrange(n): for i in range(n):
for (([x1, y1, z1], v1, m1), for (([x1, y1, z1], v1, m1),
([x2, y2, z2], v2, m2)) in pairs: ([x2, y2, z2], v2, m2)) in pairs:
dx = x1 - x2 dx = x1 - x2
...@@ -129,12 +129,12 @@ def test_nbody(iterations): ...@@ -129,12 +129,12 @@ def test_nbody(iterations):
report_energy() report_energy()
times = [] times = []
for _ in xrange(iterations): for _ in range(iterations):
t0 = time.time() t0 = time()
report_energy() report_energy()
advance(0.01, 20000) advance(0.01, 20000)
report_energy() report_energy()
t1 = time.time() t1 = time()
times.append(t1 - t0) times.append(t1 - t0)
return times return times
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment