Ticket #9542: trac_9542-znpoly_timing.patch
File trac_9542-znpoly_timing.patch, 3.7 KB (added by , 12 years ago) |
---|
-
sage/misc/all.py
diff -r bb846fce03db -r 59e8946ca592 sage/misc/all.py
a b 13 13 14 14 from html import html 15 15 16 from sage_timeit_class import timeit 16 from sage_timeit_class import timeit, test_timing 17 17 18 18 from edit_module import edit, set_edit_template 19 19 -
sage/misc/sage_timeit_class.pyx
diff -r bb846fce03db -r 59e8946ca592 sage/misc/sage_timeit_class.pyx
a b 82 82 print self.eval(code, globals, preparse=preparse, **kwds) 83 83 84 84 timeit = SageTimeit() 85 86 87 88 89 from misc import cputime, walltime 90 import preparser 91 def test_timing(code, max_cputime, max_walltime=0, loops=1): 92 G = globals() 93 code0 = code; code = preparser.preparse(code) 94 t = cputime(); w = walltime() 95 for i in range(loops): 96 eval(code, G) 97 if max_cputime>0 and cputime(t) > max_cputime: 98 print "CPU time (%s) exceeded evaluating '%s' %s times"%(max_cputime, code0, loops) 99 if max_walltime>0 and walltime(w) > max_walltime: 100 print "WALL time (%s) exceeded evaluating '%s' %s times"%(max_walltime, code0, loops) 101 85 102 86 103 -
sage/rings/polynomial/polynomial_template.pxi
diff -r bb846fce03db -r 59e8946ca592 sage/rings/polynomial/polynomial_template.pxi
a b 198 198 cdef cparent _parent = get_cparent((<Polynomial_template>self)._parent) 199 199 return [self[i] for i in range(celement_len(&self.x, _parent))] 200 200 201 def __de alloc__(self):201 def __del__(self): 202 202 """ 203 203 EXAMPLE:: 204 204 -
sage/rings/polynomial/polynomial_zmod_flint.pyx
diff -r bb846fce03db -r 59e8946ca592 sage/rings/polynomial/polynomial_zmod_flint.pyx
a b 37 37 from sage.structure.factorization import Factorization 38 38 from sage.structure.element import coerce_binop 39 39 40 from sage.structure.parent cimport Parent 41 40 42 # We need to define this stuff before including the templating stuff 41 43 # to make sure the function get_cparent is found since it is used in 42 44 # 'polynomial_template.pxi'. … … 99 101 pass 100 102 Polynomial_template.__init__(self, parent, x, check, is_gen, construct) 101 103 104 cpdef RingElement _mul_(self, RingElement right): 105 """ 106 TESTS:: 107 108 sage: R.<x> = Integers(2^6)[] 109 sage: f = R([1,2,5,-9]); g = R([1,2,3,4]) 110 sage: f*g 111 4060*x^6 + 4089*x^5 + 5*x^4 + 11*x^3 + 12*x^2 + 4*x + 1 112 sage: test_timing('f*g', 1) # optional -- timing 113 True 114 """ 115 cdef Polynomial_zmod_flint r = PY_NEW(Polynomial_zmod_flint) 116 r._parent = self._parent 117 zmod_poly_mul(&r.x, &(<Polynomial_template>self).x, &(<Polynomial_template>right).x) 118 return r 119 120 cpdef ModuleElement _add_(self, ModuleElement right): 121 cdef Polynomial_zmod_flint r = PY_NEW(Polynomial_zmod_flint) 122 r._parent = self._parent 123 zmod_poly_add(&r.x, &(<Polynomial_template>self).x, &(<Polynomial_template>right).x) 124 return r 125 126 cpdef ModuleElement _sub_(self, ModuleElement right): 127 cdef Polynomial_zmod_flint r = PY_NEW(Polynomial_zmod_flint) 128 r._parent = self._parent 129 zmod_poly_sub(&r.x, &(<Polynomial_template>self).x, &(<Polynomial_template>right).x) 130 return r 131 132 def __dealloc__(self): 133 zmod_poly_clear(&self.x) 134 102 135 cdef Polynomial_template _new(self): 103 136 """ 104 137 EXAMPLES::