question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Possible optimization?

See original GitHub issue

https://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:closed
  • Created 3 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
erezshcommented, Sep 22, 2020

Yep. I’m not sure it will be noticeable in a real task though.

0reactions
erezshcommented, May 17, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found