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 11 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") render(iset, "In-order insertion")


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


print print
yappi.start() yappi.start()
speeds = {} 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() start = time.time()
iset = IntervalSet() iset = IntervalSet()
for i in random.sample(xrange(j),j): for i in random.sample(xrange(j),j):
interval = Interval(i, i+1) interval = Interval(i, i+1)
iset += interval iset += interval
speed = (time.time() - start) * 1000000.0 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 speeds[j] = speed
aplotter.plot(speeds.keys(), speeds.values(), plot_slope=True) aplotter.plot(speeds.keys(), speeds.values(), plot_slope=True)
yappi.stop() yappi.stop()


Loading…
Cancel
Save