Changes between Initial Version and Version 9 of Ticket #17021


Ignore:
Timestamp:
Sep 28, 2014, 1:59:36 PM (8 years ago)
Author:
slabbe
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #17021

    • Property Status changed from new to needs_work
    • Property Commit changed from to 9008b8d2986614ece259a54274ae054ef5fad40d
    • Property Cc ​sstarosta added
    • Property Branch changed from to u/slabbe/17021
  • Ticket #17021 – Description

    initial v9  
    111. Move the code of {{{_construct_word}}} into {{{__call__}}} method.
    22
    3 2. Create {{{finite_word_list}}} methods which are shortcuts for {{{__call__}}} when we know the datatype.
     32. Create {{{_word_from_list}}} methods which are shortcuts for {{{__call__}}} when we know the datatype.
    44
    55Here are some benchmarks:
     
    1010sage: W = Words()
    1111sage: 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
     12sage: %timeit W.call__old(L)             # before
     1310000 loops, best of 3: 45.1 µs per loop
     14
     15sage: %timeit W(L)                       # after
     1610000 loops, best of 3: 17.1 µs per loop 
     17sage: %timeit W(L, check=False)     
     18100000 loops, best of 3: 2.21 µs per loop
     19sage: %timeit W._word_from_list(L) 
     201000000 loops, best of 3: 1.33 µs per loop
    1621}}}
    1722
     
    2126sage: W = Words()
    2227sage: 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
     28sage: %timeit W.call__old(s)              # before
     2910000 loops, best of 3: 45.7 µs per loop   
     30sage: %timeit W(s)                        # after
     3110000 loops, best of 3: 18.4 µs per loop 
     32sage: %timeit W(s, check=False)           
     33100000 loops, best of 3: 2.62 µs per loop
     34sage: %timeit W._word_from_str(s)         
     351000000 loops, best of 3: 1.23 µs per loop
    2736}}}
    2837
     
    3140{{{
    3241sage: 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
     42sage: %timeit W.call__old(t)             # before
     4310000 loops, best of 3: 45.9 µs per loop
     44sage: %timeit W(t)                       # after
     4510000 loops, best of 3: 18.6 µs per loop
     46sage: %timeit W(t,check=False)           
     47100000 loops, best of 3: 3.25 µs per loop
     48sage: %timeit W._word_from_tuple(t)     
     491000000 loops, best of 3: 1.3 µs per loop
    3750}}}
    3851
    39 char (why creation is so longer than str, tuple or list?):
     52char (here creation is longer than str, tuple or list because a copy of data is performed):
    4053
    4154{{{
     
    4457sage: type(W(L))
    4558<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
     59sage: %timeit W.call__old(L)           # before
     601000 loops, best of 3: 322 µs per loop
     61sage: %timeit W(L)                     # after
     621000 loops, best of 3: 292 µs per loop
     63sage: %timeit W(L, check=False)       
     641000 loops, best of 3: 248 µs per loop
     65sage: %timeit W._word_from_char(L)   
     661000 loops, best of 3: 245 µs per loop
    5067}}}
    5168
     
    5976}}}
    6077
    61 AFTER:
     78AFTER (about 20 times faster):
    6279
    6380{{{
    6481sage: W = Words(range(5))
    6582sage: %time L = list(W.iterate_by_length(7))
    66 CPU times: user 940 ms, sys: 80.4 ms, total: 1.02 s
    67 Wall time: 1.02 s
     83CPU times: user 235 ms, sys: 29.1 ms, total: 264 ms
     84Wall time: 259 ms                                 
    6885}}}