def tabulate(r):
    """Tabulate sort speed for lists of various sizes.

    The sizes are 2**i for i in r (the argument, a list).

    The output displays i, 2**i, and the time to sort arrays of 2**i
    floating point numbers with the following properties:

    *sort: random data
    \sort: descending data
    /sort: ascending data
    3sort: ascending, then 3 random exchanges
    +sort: ascending, then 10 random at the end
    %sort: ascending, then randomly replace 1% of the elements w/ random values
    ~sort: many duplicates
    =sort: all equal
    !sort: worst case scenario

    """
    cases = tuple([ch + "sort" for ch in r"*\/3+%~=!"])
    fmt = ("%2s %7s" + " %6s"*len(cases))
    print (("i", "2**i") + cases) % fmt
    for i in r:
        n = 1 << i
        L = randfloats(n)
        print "%2d %7d" % (i, n),
        flush()
        doit(L) # *sort
        L.reverse()
        doit(L) # \sort
        doit(L) # /sort

        # Do 3 random exchanges.
        for dummy in range(3):
            i1 = random.randrange(n)
            i2 = random.randrange(n)
            L[i1], L[i2] = L[i2], L[i1]
        doit(L) # 3sort

        # Replace the last 10 with random floats.
        if n >= 10:
            L[-10:] = [random.random() for dummy in range(10)]
        doit(L) # +sort

        # Replace 1% of the elements at random.
        for dummy in xrange(n // 100):
            L[random.randrange(n)] = random.random()
        doit(L) # %sort

        # Arrange for lots of duplicates.
        if n > 4:
            del L[4:]
            L = L * (n // 4)
            # Force the elements to be distinct objects, else timings can be
            # artificially low.
            L = map(lambda x: --x, L)
        doit(L) # ~sort
        del L

        # All equal.  Again, force the elements to be distinct objects.
        L = map(abs, [-0.5] * n)
        doit(L) # =sort
        del L

        # This one looks like [3, 2, 1, 0, 0, 1, 2, 3].  It was a bad case
        # for an older implementation of quicksort, which used the median
        # of the first, last and middle elements as the pivot.
        half = n // 2
        L = range(half - 1, -1, -1)
        L.extend(range(half))
        # Force to float, so that the timings are comparable.  This is
        # significantly faster if we leave tham as ints.
        L = map(float, L)
        doit(L) # !sort
        print
dataset/ETHPy150Open azoft-dev-team/imagrium/env/Lib/test/sortperf.py/tabulate/swapped operands of `%`