Browse Source

Speed tests.

test_interval_speed is about O(n * log n), which is good -- but the
constants are high and it hits swap on a 4G machine for the 2**21
test.  Hopefully cython helps!
tags/before-insert-rework
Jim Paris 9 years ago
parent
commit
f5c60f68dc
1 changed files with 8 additions and 3 deletions
  1. +8
    -3
      tests/test_interval.py

+ 8
- 3
tests/test_interval.py View File

@@ -325,24 +325,29 @@ class TestIntervalTree:
render(iset, "In-order insertion")

class TestIntervalSpeed:
@unittest.skip("this is slow")
#@unittest.skip("this is slow")
def test_interval_speed(self):
import yappi
import time
import aplotter
import random
import math

print
yappi.start()
speeds = {}
for j in [ 2**x for x in range(5,18) ]:
for j in [ 2**x for x in range(5,21) ]:
start = time.time()
iset = IntervalSet()
for i in random.sample(xrange(j),j):
interval = Interval(i, i+1)
iset += interval
speed = (time.time() - start) * 1000000.0
printf("%d: %g μs (%g μs each)\n", j, speed, speed/j)
printf("%d: %g μs (%g μs each, O(n log n) ratio %g)\n",
j,
speed,
speed/j,
speed / (j*math.log(j))) # should be constant
speeds[j] = speed
aplotter.plot(speeds.keys(), speeds.values(), plot_slope=True)
yappi.stop()


Loading…
Cancel
Save