From f5c60f68dc2e5ed116d91f271cc989876d6658f2 Mon Sep 17 00:00:00 2001 From: Jim Paris Date: Thu, 29 Nov 2012 01:00:54 -0500 Subject: [PATCH] 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! --- tests/test_interval.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/test_interval.py b/tests/test_interval.py index b207330..c55d724 100644 --- a/tests/test_interval.py +++ b/tests/test_interval.py @@ -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()