Draft
Conversation
khaledhosny
reviewed
Oct 27, 2021
0d16d02 to
5704db8
Compare
Collaborator
Author
|
I was going to rewrite the 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
See #733.