Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# -*- coding: utf-8 -*- Performance Test for Clone Protocol
see :class:`sage.structure.list_clone.ClonableArray`
EXAMPLES::
sage: from sage.structure.list_clone_timings import * sage: cmd =["", ....: "e.__copy__()", ....: "copy(e)", ....: "e.clone()", ....: "e.__class__(e.parent(), e._get_list())", ....: "e.__class__(e.parent(), e[:])", ....: "e.check()", ....: "", ....: "add1_internal(e)", ....: "add1_immutable(e)", ....: "add1_mutable(e)", ....: "add1_with(e)", ....: "", ....: "cy_add1_internal(e)", ....: "cy_add1_immutable(e)", ....: "cy_add1_mutable(e)", ....: "cy_add1_with(e)"]
Various timings using a Cython class::
sage: size = 5 sage: e = IncreasingArrays()(range(size)) sage: # random ....: for p in cmd: ....: print("{0:36} : ".format(p), end=""); timeit(p) : e.__copy__() : 625 loops, best of 3: 446 ns per loop copy(e) : 625 loops, best of 3: 1.94 µs per loop e.clone() : 625 loops, best of 3: 736 ns per loop e.__class__(e.parent(), e._get_list()) : 625 loops, best of 3: 1.34 µs per loop e.__class__(e.parent(), e[:]) : 625 loops, best of 3: 1.35 µs per loop e.check() : 625 loops, best of 3: 342 ns per loop : add1_internal(e) : 625 loops, best of 3: 3.53 µs per loop add1_immutable(e) : 625 loops, best of 3: 3.72 µs per loop add1_mutable(e) : 625 loops, best of 3: 3.42 µs per loop add1_with(e) : 625 loops, best of 3: 4.05 µs per loop : cy_add1_internal(e) : 625 loops, best of 3: 752 ns per loop cy_add1_immutable(e) : 625 loops, best of 3: 1.28 µs per loop cy_add1_mutable(e) : 625 loops, best of 3: 861 ns per loop cy_add1_with(e) : 625 loops, best of 3: 1.51 µs per loop
Various timings using a Python class::
sage: e = IncreasingArraysPy()(range(size)) sage: # random ....: for p in cmd: print("{0:36} : ".format(p), end=""); timeit(p) : e.__copy__() : 625 loops, best of 3: 869 ns per loop copy(e) : 625 loops, best of 3: 2.13 µs per loop e.clone() : 625 loops, best of 3: 1.86 µs per loop e.__class__(e.parent(), e._get_list()) : 625 loops, best of 3: 7.52 µs per loop e.__class__(e.parent(), e[:]) : 625 loops, best of 3: 7.27 µs per loop e.check() : 625 loops, best of 3: 4.02 µs per loop : add1_internal(e) : 625 loops, best of 3: 9.34 µs per loop add1_immutable(e) : 625 loops, best of 3: 9.91 µs per loop add1_mutable(e) : 625 loops, best of 3: 12.6 µs per loop add1_with(e) : 625 loops, best of 3: 15.9 µs per loop : cy_add1_internal(e) : 625 loops, best of 3: 7.13 µs per loop cy_add1_immutable(e) : 625 loops, best of 3: 6.95 µs per loop cy_add1_mutable(e) : 625 loops, best of 3: 14.1 µs per loop cy_add1_with(e) : 625 loops, best of 3: 17.5 µs per loop """ #***************************************************************************** # Copyright (C) 2009-2010 Florent Hivert <Florent.Hivert@univ-rouen.fr> # # Distributed under the terms of the GNU General Public License (GPL) # http://www.gnu.org/licenses/ #*****************************************************************************
""" A small class for testing :class:`ClonableArray`: Increasing Lists
TESTS::
sage: from sage.structure.list_clone_timings import IncreasingArraysPy sage: TestSuite(IncreasingArraysPy()([1,2,3])).run() """
""" Check that ``self`` is increasing.
EXAMPLES::
sage: from sage.structure.list_clone_timings import IncreasingArraysPy sage: IncreasingArraysPy()([1,2,3]) # indirect doctest [1, 2, 3] sage: IncreasingArraysPy()([3,2,1]) # indirect doctest Traceback (most recent call last): ... ValueError: Lists is not increasing """
##################################################################### ###### Timings functions ###### ##################################################################### """ TESTS::
sage: from sage.structure.list_clone_timings import * sage: add1_internal(IncreasingArrays()([1,4,5])) [2, 5, 6] """
""" TESTS::
sage: from sage.structure.list_clone_timings import * sage: add1_immutable(IncreasingArrays()([1,4,5])) [2, 5, 6] """
""" TESTS::
sage: from sage.structure.list_clone_timings import * sage: add1_mutable(IncreasingArrays()([1,4,5])) [2, 5, 6] """
""" TESTS::
sage: from sage.structure.list_clone_timings import * sage: add1_with(IncreasingArrays()([1,4,5])) [2, 5, 6] """ |