Changes between Initial Version and Version 9 of Ticket #17021
- Timestamp:
- Sep 28, 2014, 1:59:36 PM (8 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #17021
-
Property
Status
changed from
new
toneeds_work
-
Property
Commit
changed from
to
9008b8d2986614ece259a54274ae054ef5fad40d
- Property Cc sstarosta added
-
Property
Branch
changed from
to
u/slabbe/17021
-
Property
Status
changed from
-
Ticket #17021 – Description
initial v9 1 1 1. Move the code of {{{_construct_word}}} into {{{__call__}}} method. 2 2 3 2. Create {{{ finite_word_list}}} methods which are shortcuts for {{{__call__}}} when we know the datatype.3 2. Create {{{_word_from_list}}} methods which are shortcuts for {{{__call__}}} when we know the datatype. 4 4 5 5 Here are some benchmarks: … … 10 10 sage: W = Words() 11 11 sage: L = range(1000) 12 sage: %timeit W(L) 13 10000 loops, best of 3: 45.5 µs per loop 14 sage: %timeit W.finite_word_list(L) 15 1000000 loops, best of 3: 1.29 µs per loop 12 sage: %timeit W.call__old(L) # before 13 10000 loops, best of 3: 45.1 µs per loop 14 15 sage: %timeit W(L) # after 16 10000 loops, best of 3: 17.1 µs per loop 17 sage: %timeit W(L, check=False) 18 100000 loops, best of 3: 2.21 µs per loop 19 sage: %timeit W._word_from_list(L) 20 1000000 loops, best of 3: 1.33 µs per loop 16 21 }}} 17 22 … … 21 26 sage: W = Words() 22 27 sage: s = 'a'*1000 23 sage: %timeit W(s) 24 10000 loops, best of 3: 45.2 µs per loop 25 sage: %timeit W.finite_word_str(s) 26 1000000 loops, best of 3: 1.27 µs per loop 28 sage: %timeit W.call__old(s) # before 29 10000 loops, best of 3: 45.7 µs per loop 30 sage: %timeit W(s) # after 31 10000 loops, best of 3: 18.4 µs per loop 32 sage: %timeit W(s, check=False) 33 100000 loops, best of 3: 2.62 µs per loop 34 sage: %timeit W._word_from_str(s) 35 1000000 loops, best of 3: 1.23 µs per loop 27 36 }}} 28 37 … … 31 40 {{{ 32 41 sage: t = tuple(L) 33 sage: %timeit W(t) 34 10000 loops, best of 3: 46 µs per loop 35 sage: %timeit W.finite_word_tuple(t) 36 1000000 loops, best of 3: 1.39 µs per loop 42 sage: %timeit W.call__old(t) # before 43 10000 loops, best of 3: 45.9 µs per loop 44 sage: %timeit W(t) # after 45 10000 loops, best of 3: 18.6 µs per loop 46 sage: %timeit W(t,check=False) 47 100000 loops, best of 3: 3.25 µs per loop 48 sage: %timeit W._word_from_tuple(t) 49 1000000 loops, best of 3: 1.3 µs per loop 37 50 }}} 38 51 39 char ( why creation is so longer than str, tuple or list?):52 char (here creation is longer than str, tuple or list because a copy of data is performed): 40 53 41 54 {{{ … … 44 57 sage: type(W(L)) 45 58 <class 'sage.combinat.words.word.FiniteWord_char'> 46 sage: %timeit W(L) 47 1000 loops, best of 3: 336 µs per loop 48 sage: %timeit W.finite_word_char(L) 49 1000 loops, best of 3: 246 µs per loop 59 sage: %timeit W.call__old(L) # before 60 1000 loops, best of 3: 322 µs per loop 61 sage: %timeit W(L) # after 62 1000 loops, best of 3: 292 µs per loop 63 sage: %timeit W(L, check=False) 64 1000 loops, best of 3: 248 µs per loop 65 sage: %timeit W._word_from_char(L) 66 1000 loops, best of 3: 245 µs per loop 50 67 }}} 51 68 … … 59 76 }}} 60 77 61 AFTER :78 AFTER (about 20 times faster): 62 79 63 80 {{{ 64 81 sage: W = Words(range(5)) 65 82 sage: %time L = list(W.iterate_by_length(7)) 66 CPU times: user 940 ms, sys: 80.4 ms, total: 1.02s67 Wall time: 1.02 s83 CPU times: user 235 ms, sys: 29.1 ms, total: 264 ms 84 Wall time: 259 ms 68 85 }}}