Skip to content

The with statement might be loosing accuracy? #9

@Erotemic

Description

@Erotemic

It might be better to get timing information without the "with" statement.

See:

"""
Inspired by https://www.youtube.com/watch?v=XThL0LP3RjY
"""


def main():
    import timerit
    import ubelt as ub
    expected = "58178059833426840615453390153965"

    variants = dict(
        ne_01=expected[0: 0] + 'F' + expected[ 1:32],
        ne_16=expected[0:15] + 'F' + expected[16:32],
        ne_32=expected[0:31] + 'F' + expected[32:32],
        too_long='F' * len(expected) * 10,
        too_short='F',
    )

    ti = timerit.Timerit(1000000, bestof=10, verbose=2)

    for key, value in variants.items():
        for timer in ti.reset(key):
            value == expected

    print('ti.rankings = {}'.format(ub.repr2(
        ti.rankings['min'], nl=2, align=':', precision=12)))


if __name__ == '__main__':
    """
    CommandLine:
        python ~/misc/tests/python/test_equality_time.py
    """
    main()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions