1 # This Python file uses the following encoding: utf-8
3 Created on May 14, 2011
5 This class was to test the functionality and performance of a deduction
6 iterator which accumulated partial results through tuple addition,
7 against one returned it as a growing deque. their performance was
14 from itertools
import chain
, combinations
15 from mjacob
.algorithms
.deduction_iterator
import deductions
18 go
= "for ded in deductions(start, A.__getitem__):pass"
23 for g
in chain(*[combinations(range(n
), m
)
24 for m
in range(n
+1)]) # xrange(4)
28 #A = dict((i, tuple((j,k) for j,k in product(xrange(n+1), xrange(n+1,n+n+2)) if j is not i and k is not i)) for i in xrange(n+n+1) if i != n)
29 #print "\n".join(str(x) for x in sorted(A.items()))
33 for d
in deductions(0, A
.__getitem
__):
34 if len(d
) < n
: continue
35 #print u"; ".join(u"%s -> %s" % (",".join(str(x[j]) for j in b), x[a]) for a,b in d)
38 print("%s %s" % (n
, m
))
39 for d
in ("deduction_iterator", "deduction_iterator3"):
42 from algorithms.%s import deductions
43 from itertools import product
48 timer
= timeit
.Timer(go
, prep
)
50 print("%s %s (%s): %.2f ms/pass" % (d
, n
, m
, 1000 * timer
.timeit(number
=1)))