Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance work #740

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Performance work #740

wants to merge 1 commit into from

Conversation

madig
Copy link
Collaborator

@madig madig commented Oct 27, 2021

See #733.

@madig
Copy link
Collaborator Author

madig commented Oct 27, 2021

I was going to rewrite the parse_float_or_int function like so:

def parse_float_or_int(value_string):
    # NOTE: Profile any changes you make to this function, as it is in the hot
    # file loading path. E.g.
    #
    #   In [32]: %timeit parse_float_or_int("2000")
    #       ...: %timeit parse_float_or_int("-2000")
    #       ...: %timeit parse_float_or_int("123.456")
    #       ...: %timeit parse_float_or_int("-123.456")
    #   183 ns ± 1.11 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)
    #   186 ns ± 0.614 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
    #   199 ns ± 2.69 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
    #   201 ns ± 1.56 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
    #
    # There's another way of writing it:
    #
    #   In [2]: def parse_float_or_int2(value_string):
    #      ...:     try:
    #      ...:         return int(value_string)
    #      ...:     except ValueError:
    #      ...:         return float(value_string)
    #
    # The usual case of integers parses slighly faster, but as of Python 3.9.7, the
    # exceptional case of floating point coordinates is much slower.
    #
    #     In [36]: %timeit parse_float_or_int2("2000")
    #         ...: %timeit parse_float_or_int2("-2000")
    #         ...: %timeit parse_float_or_int2("123.456")
    #         ...: %timeit parse_float_or_int2("-123.456")
    #       170 ns ± 1.46 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)
    #       173 ns ± 2.41 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)
    #       1.18 µs ± 10.3 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
    #       1.19 µs ± 7.65 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
    #
    if "." in value_string:
        return float(value_string)
    return int(value_string)

but apparently it is not necessarily called with a string but also floats and ints in various places?????

Another stumbling block is the function behavior, for "100.0" it will return int(100); changing this makes some equivalence tests fail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants