Possible optimization?
See original GitHub issuehttps://github.com/lark-parser/lark/blob/7c8d6ee787692f7287d38de92d06174bf956d72a/lark/lexer.py#L193 to
lenstream = len(stream)
while line_ctrl.char_pos < lenstream:
...
In [1]: stream = ' ' * int(1e6)
In [2]: %timeit for _ in range(int(1e6)): len(stream)
71.9 ms ± 3.54 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
In [3]: lenstream = len(stream)
In [4]: %timeit for _ in range(int(1e6)): lenstream
30.7 ms ± 853 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (6 by maintainers)
Top Results From Across the Web
Optimization - Calculus I - Pauls Online Math Notes
In this section we are going to look at optimization problems. ... In this method we also will need an interval of possible...
Read more >Mathematical optimization - Wikipedia
More generally, optimization includes finding "best available" values of some objective function given a defined domain (or input), including a variety of ...
Read more >6.1 Optimization
Many important applied problems involve finding the best way to accomplish some task. Often this involves finding the maximum or minimum value of...
Read more >5.8 Optimization Problems
Guideline for Solving Optimization Problems. Identify what is to be maximized or minimized and what the constraints are. Draw a diagram (if appropriate)...
Read more >Optimization | Definition, Techniques, & Facts | Britannica
optimization, also known as mathematical programming, collection of ... among a finite but very large set of possible values, such as the many...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yep. I’m not sure it will be noticeable in a real task though.
Thanks Ludwig! I’ll close this now unless someone’s benchmark shows otherwise 😃
@pwwang Personal computers usually aren’t tuned for benchmarking. There’s random processes popping up, the cpu may change speed according to temperature, and other such pitfalls. I would guess that many of the differences are due to such random circumstances.