Skip to content

Commit bbc4488

Browse files
author
jimmieha
committed
profilers added
1 parent e874f2a commit bbc4488

File tree

4 files changed

+318
-0
lines changed

4 files changed

+318
-0
lines changed

profile_results/pyecm.py.cProfile

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
Factoring 10000000000000000000000000000000000000000000000001:
2+
11
3+
197
4+
909091
5+
5076141624365532994918781726395939035533
6+
21897 function calls in 0.432 CPU seconds
7+
8+
Ordered by: standard name
9+
10+
ncalls tottime percall cumtime percall filename:lineno(function)
11+
1 0.000 0.000 0.000 0.000 <string>:1(<module>)
12+
1 0.000 0.000 0.000 0.000 __future__.py:48(<module>)
13+
1 0.000 0.000 0.000 0.000 __future__.py:74(_Feature)
14+
7 0.000 0.000 0.000 0.000 __future__.py:75(__init__)
15+
1 0.000 0.000 0.000 0.000 os.py:743(urandom)
16+
1 0.002 0.002 0.003 0.003 pyecm.py:1034(get_points)
17+
3 0.000 0.000 0.013 0.004 pyecm.py:1075(isprime)
18+
3 0.000 0.000 0.240 0.080 pyecm.py:1137(ecm)
19+
5 0.007 0.001 0.380 0.076 pyecm.py:1235(factors)
20+
2 0.000 0.000 0.000 0.000 pyecm.py:1287(is_switch)
21+
8915 0.130 0.000 0.133 0.000 pyecm.py:131(next_prime)
22+
2 0.000 0.000 0.000 0.000 pyecm.py:1316(valid_input)
23+
1 0.000 0.000 0.380 0.380 pyecm.py:1357(command_line)
24+
1 0.000 0.000 0.380 0.380 pyecm.py:1435(main)
25+
1 0.015 0.015 0.400 0.400 pyecm.py:15(<module>)
26+
95 0.000 0.000 0.000 0.000 pyecm.py:182(mpz)
27+
3 0.001 0.000 0.001 0.000 pyecm.py:188(root)
28+
3 0.000 0.000 0.001 0.000 pyecm.py:205(sqrt)
29+
1 0.000 0.000 0.000 0.000 pyecm.py:235(ts)
30+
8 0.003 0.000 0.008 0.001 pyecm.py:325(add)
31+
4 0.000 0.000 0.000 0.000 pyecm.py:36(gcd)
32+
72 0.009 0.000 0.009 0.000 pyecm.py:373(atdn)
33+
1 0.000 0.000 0.000 0.000 pyecm.py:388(copy)
34+
3 0.000 0.000 0.003 0.001 pyecm.py:398(could_be_prime)
35+
208 0.095 0.000 0.204 0.001 pyecm.py:432(double)
36+
3 0.000 0.000 0.003 0.001 pyecm.py:455(fastprime)
37+
3 0.000 0.000 0.000 0.000 pyecm.py:519(inv_const)
38+
2 0.000 0.000 0.000 0.000 pyecm.py:525(naf)
39+
230 0.054 0.000 0.120 0.001 pyecm.py:539(parallel_invert)
40+
18 0.000 0.000 0.000 0.000 pyecm.py:558(prod)
41+
13 0.005 0.000 0.012 0.001 pyecm.py:754(subtract)
42+
230 0.066 0.000 0.066 0.000 pyecm.py:77(invert)
43+
1 0.000 0.000 0.000 0.000 pyecm.py:775(congrats)
44+
3 0.000 0.000 0.240 0.080 pyecm.py:786(sure_factors)
45+
1 0.000 0.000 0.000 0.000 pyecm.py:827(to_tuple)
46+
1 0.001 0.001 0.228 0.228 pyecm.py:837(mainloop)
47+
1 0.000 0.000 0.076 0.076 pyecm.py:994(fast_multiply)
48+
1 0.004 0.004 0.005 0.005 random.py:40(<module>)
49+
1 0.000 0.000 0.000 0.000 random.py:643(WichmannHill)
50+
1 0.000 0.000 0.000 0.000 random.py:71(Random)
51+
1 0.000 0.000 0.000 0.000 random.py:793(SystemRandom)
52+
1 0.000 0.000 0.000 0.000 random.py:90(__init__)
53+
1 0.000 0.000 0.000 0.000 random.py:99(seed)
54+
1 0.000 0.000 0.000 0.000 {binascii.hexlify}
55+
1 0.000 0.000 0.000 0.000 {eval}
56+
1 0.032 0.032 0.432 0.432 {execfile}
57+
1 0.000 0.000 0.000 0.000 {function seed at 0x100530938}
58+
404 0.000 0.000 0.000 0.000 {isinstance}
59+
1321 0.000 0.000 0.000 0.000 {len}
60+
1 0.000 0.000 0.000 0.000 {math.exp}
61+
9611 0.003 0.000 0.003 0.000 {math.log}
62+
3 0.000 0.000 0.000 0.000 {math.sqrt}
63+
20 0.000 0.000 0.000 0.000 {max}
64+
440 0.000 0.000 0.000 0.000 {method 'append' of 'list' objects}
65+
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
66+
1 0.000 0.000 0.000 0.000 {method 'replace' of 'str' objects}
67+
2 0.000 0.000 0.000 0.000 {min}
68+
1 0.000 0.000 0.000 0.000 {posix.close}
69+
1 0.000 0.000 0.000 0.000 {posix.open}
70+
1 0.000 0.000 0.000 0.000 {posix.read}
71+
231 0.000 0.000 0.000 0.000 {range}
72+
73+
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
Timer unit: 1e-06 s
2+
3+
File: pyecm.py
4+
Function: invert at line 76
5+
Total time: 0.427487 s
6+
7+
Line # Hits Time Per Hit % Time Line Contents
8+
==============================================================
9+
76 @profile
10+
77 def invert(a, b):
11+
78 '''Computes the inverse of a modulo b. b must be odd.
12+
79
13+
80 Returns the inverse of a (mod b).'''
14+
81 230 403 1.8 0.1 if a == 0 or b == 0:
15+
82 return 0
16+
83
17+
84 230 249 1.1 0.1 truth = False
18+
85 230 255 1.1 0.1 if a < 0:
19+
86 truth = True
20+
87 a = -a
21+
88
22+
89 230 212 0.9 0.0 b_orig = b
23+
90 230 211 0.9 0.0 alpha = 1
24+
91 230 222 1.0 0.1 beta = 0
25+
92
26+
93 424 569 1.3 0.1 while not a & 1:
27+
94 194 226 1.2 0.1 if alpha & 1:
28+
95 112 163 1.5 0.0 alpha += b_orig
29+
96 194 252 1.3 0.1 alpha >>= 1
30+
97 194 218 1.1 0.1 a >>= 1
31+
98
32+
99 230 248 1.1 0.1 if b > a:
33+
100 230 239 1.0 0.1 a, b = b, a
34+
101 230 241 1.0 0.1 alpha, beta = beta, alpha
35+
102
36+
103 24834 29747 1.2 7.0 while b != 0 and a != b:
37+
104 24604 26940 1.1 6.3 a -= b
38+
105 24604 26910 1.1 6.3 alpha -= beta
39+
106
40+
107 73584 86906 1.2 20.3 while not a & 1:
41+
108 48980 55889 1.1 13.1 if alpha & 1:
42+
109 25106 28201 1.1 6.6 alpha += b_orig
43+
110 48980 59761 1.2 14.0 alpha >>= 1
44+
111 48980 55045 1.1 12.9 a >>= 1
45+
112
46+
113 24604 25288 1.0 5.9 if b > a:
47+
114 13156 13600 1.0 3.2 a,b = b,a
48+
115 13156 13544 1.0 3.2 alpha, beta = beta, alpha
49+
116
50+
117 230 235 1.0 0.1 if a == b:
51+
118 230 261 1.1 0.1 a -= b
52+
119 230 258 1.1 0.1 alpha -= beta
53+
120 230 235 1.0 0.1 a, b = b, a
54+
121 230 245 1.1 0.1 alpha, beta = beta, alpha
55+
122
56+
123 230 268 1.2 0.1 if a != 1:
57+
124 1 1 1.0 0.0 return 0
58+
125
59+
126 229 227 1.0 0.1 if truth:
60+
127 alpha = b_orig - alpha
61+
128
62+
129 229 218 1.0 0.1 return alpha
63+
64+
File: pyecm.py
65+
Function: double at line 431
66+
Total time: 1.27076 s
67+
68+
Line # Hits Time Per Hit % Time Line Contents
69+
==============================================================
70+
431 @profile
71+
432 def double(p, n):
72+
433 '''Doubles each point in the input list. Much like the add function, we take advantage of fast inversion.
73+
434
74+
435 Returns the doubled list.'''
75+
436 208 922 4.4 0.1 inv = range(len(p))
76+
437
77+
438 19136 19680 1.0 1.5 for i in xrange(len(p)):
78+
439 18928 26903 1.4 2.1 inv[i] = p[i][1] << 1
79+
440
80+
441 208 998041 4798.3 78.5 inv = parallel_invert(inv, n)
81+
442
82+
443 208 421 2.0 0.0 if not isinstance(inv, list):
83+
444 return inv
84+
445
85+
446 19136 20290 1.1 1.6 for i in xrange(len(p)):
86+
447 18928 22958 1.2 1.8 x = p[i][0]
87+
448 18928 35512 1.9 2.8 m = (x * x) % n
88+
449 18928 48911 2.6 3.8 m = ((m + m + m + p[i][2]) * inv[i]) % n
89+
450 18928 44906 2.4 3.5 p[i][0] = (m * m - x - x) % n
90+
451 18928 51985 2.7 4.1 p[i][1] = (m * (x - p[i][0]) - p[i][1]) % n
91+
452
92+
453 208 235 1.1 0.0 return p
93+
94+
File: pyecm.py
95+
Function: parallel_invert at line 538
96+
Total time: 0.971774 s
97+
98+
Line # Hits Time Per Hit % Time Line Contents
99+
==============================================================
100+
538 @profile
101+
539 def parallel_invert(l, n):
102+
540 '''Inverts all elements of a list modulo some number, using 3(n-1) modular multiplications and one inversion.
103+
541
104+
542 Returns the list with all elements inverted modulo 3(n-1).'''
105+
543 230 479 2.1 0.0 l_ = l[:]
106+
544 20930 20740 1.0 2.1 for i in xrange(len(l)-1):
107+
545 20700 43498 2.1 4.5 l[i+1] = (l[i] * l[i+1]) % n
108+
546
109+
547 230 804621 3498.4 82.8 inv = invert(l[-1], n)
110+
548 230 311 1.4 0.0 if inv == 0:
111+
549 1 435 435.0 0.0 return gcd(l[-1], n)
112+
550
113+
551 20839 21461 1.0 2.2 for i in xrange(len(l)-1, 0, -1):
114+
552 20610 41223 2.0 4.2 l[i] = (inv * l[i-1]) % n
115+
553 20610 38521 1.9 4.0 inv = (inv * l_[i]) % n
116+
554 229 254 1.1 0.0 l[0] = inv
117+
555
118+
556 229 231 1.0 0.0 return l
119+
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
test
2+
11
3+
197
4+
909091
5+
5076141624365532994918781726395939035533
6+
Filename: pyecm.py
7+
8+
Line # Mem usage Increment Line Contents
9+
================================================
10+
76 @profile
11+
77 def invert(a, b):
12+
78 '''Computes the inverse of a modulo b. b must be odd.
13+
79
14+
80 11.754 MB 0.000 MB Returns the inverse of a (mod b).'''
15+
81 28.969 MB 17.215 MB if a == 0 or b == 0:
16+
82 return 0
17+
83
18+
84 28.969 MB 0.000 MB truth = False
19+
85 28.969 MB 0.000 MB if a < 0:
20+
86 truth = True
21+
87 a = -a
22+
88
23+
89 28.969 MB 0.000 MB b_orig = b
24+
90 28.969 MB 0.000 MB alpha = 1
25+
91 22.930 MB -6.039 MB beta = 0
26+
92
27+
93 28.969 MB 6.039 MB while not a & 1:
28+
94 28.969 MB 0.000 MB if alpha & 1:
29+
95 24.012 MB -4.957 MB alpha += b_orig
30+
96 28.969 MB 4.957 MB alpha >>= 1
31+
97 28.195 MB -0.773 MB a >>= 1
32+
98
33+
99 28.969 MB 0.773 MB if b > a:
34+
100 28.969 MB 0.000 MB a, b = b, a
35+
101 11.852 MB -17.117 MB alpha, beta = beta, alpha
36+
102
37+
103 29.008 MB 17.156 MB while b != 0 and a != b:
38+
104 29.008 MB 0.000 MB a -= b
39+
105 18.379 MB -10.629 MB alpha -= beta
40+
106
41+
107 29.008 MB 10.629 MB while not a & 1:
42+
108 29.008 MB 0.000 MB if alpha & 1:
43+
109 21.496 MB -7.512 MB alpha += b_orig
44+
110 29.008 MB 7.512 MB alpha >>= 1
45+
111 29.008 MB 0.000 MB a >>= 1
46+
112
47+
113 29.008 MB 0.000 MB if b > a:
48+
114 29.008 MB 0.000 MB a,b = b,a
49+
115 29.008 MB 0.000 MB alpha, beta = beta, alpha
50+
116
51+
117 29.008 MB 0.000 MB if a == b:
52+
118 29.008 MB 0.000 MB a -= b
53+
119 29.008 MB 0.000 MB alpha -= beta
54+
120 29.008 MB 0.000 MB a, b = b, a
55+
121 29.008 MB 0.000 MB alpha, beta = beta, alpha
56+
122
57+
123 29.008 MB 0.000 MB if a != 1:
58+
124 29.008 MB 0.000 MB return 0
59+
125 11.754 MB -17.254 MB
60+
126 28.945 MB 17.191 MB if truth:
61+
127 alpha = b_orig - alpha
62+
128
63+
129 28.945 MB 0.000 MB return alpha
64+
65+
66+
Filename: pyecm.py
67+
68+
Line # Mem usage Increment Line Contents
69+
================================================
70+
538 @profile
71+
539 def parallel_invert(l, n):
72+
540 '''Inverts all elements of a list modulo some number, using 3(n-1) modular multiplications and one inversion.
73+
541
74+
542 11.746 MB 0.000 MB Returns the list with all elements inverted modulo 3(n-1).'''
75+
543 11.844 MB 0.098 MB l_ = l[:]
76+
544 28.965 MB 17.121 MB for i in xrange(len(l)-1):
77+
545 28.969 MB 0.004 MB l[i+1] = (l[i] * l[i+1]) % n
78+
546
79+
547 29.008 MB 0.039 MB inv = invert(l[-1], n)
80+
548 29.008 MB 0.000 MB if inv == 0:
81+
549 29.008 MB 0.000 MB return gcd(l[-1], n)
82+
550 11.754 MB -17.254 MB
83+
551 28.949 MB 17.195 MB for i in xrange(len(l)-1, 0, -1):
84+
552 28.949 MB 0.000 MB l[i] = (inv * l[i-1]) % n
85+
553 28.949 MB 0.000 MB inv = (inv * l_[i]) % n
86+
554 28.949 MB 0.000 MB l[0] = inv
87+
555
88+
556 28.949 MB 0.000 MB return l
89+
90+
91+
Filename: pyecm.py
92+
93+
Line # Mem usage Increment Line Contents
94+
================================================
95+
431 @profile
96+
432 def double(p, n):
97+
433 '''Doubles each point in the input list. Much like the add function, we take advantage of fast inversion.
98+
434
99+
435 11.770 MB 0.000 MB Returns the doubled list.'''
100+
436 11.902 MB 0.133 MB inv = range(len(p))
101+
437
102+
438 28.887 MB 16.984 MB for i in xrange(len(p)):
103+
439 28.887 MB 0.000 MB inv[i] = p[i][1] << 1
104+
440
105+
441 28.949 MB 0.062 MB inv = parallel_invert(inv, n)
106+
442
107+
443 11.973 MB -16.977 MB if not isinstance(inv, list):
108+
444 return inv
109+
445
110+
446 28.961 MB 16.988 MB for i in xrange(len(p)):
111+
447 28.961 MB 0.000 MB x = p[i][0]
112+
448 28.961 MB 0.000 MB m = (x * x) % n
113+
449 28.961 MB 0.000 MB m = ((m + m + m + p[i][2]) * inv[i]) % n
114+
450 28.961 MB 0.000 MB p[i][0] = (m * m - x - x) % n
115+
451 28.961 MB 0.000 MB p[i][1] = (m * (x - p[i][0]) - p[i][1]) % n
116+
452
117+
453 28.961 MB 0.000 MB return p
118+
119+

profile_results/pyecm.py.plop

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Factoring 10000000000000000000000000000000000000000000000001:
2+
11
3+
197
4+
909091
5+
5076141624365532994918781726395939035533
6+
profile output saved to /tmp/plop.out
7+
overhead was 2.93319289749e-05 per sample (0.00293319289749%)

0 commit comments

Comments
 (0)