ruff/crates
Christian Clauss 33e9a6a54e
SIM110: any() is ~3x slower than the code it replaces (#12746)
> ~Builtins are also more efficient than `for` loops.~

Let's not promise performance because this code transformation does not
deliver.

Benchmark written by @dcbaker

> `any()` seems to be about 1/3 as fast (Python 3.11.9, NixOS):
```python
loop = 'abcdef'.split()
found = 'f'
nfound = 'g'


def test1():
    for x in loop:
        if x == found:
            return True
    return False


def test2():
    return any(x == found for x in loop)


def test3():
    for x in loop:
        if x == nfound:
            return True
    return False


def test4():
    return any(x == nfound for x in loop)


if __name__ == "__main__":
    import timeit

    print('for loop (found)    :', timeit.timeit(test1))
    print('for loop (not found):', timeit.timeit(test3))
    print('any() (found)       :', timeit.timeit(test2))
    print('any() (not found)   :', timeit.timeit(test4))
```
```
for loop (found)    : 0.051076093994197436
for loop (not found): 0.04388196699437685
any() (found)       : 0.15422860698890872
any() (not found)   : 0.15568504799739458
```
I have retested with longer lists and on multiple Python versions with
similar results.
2024-08-08 08:25:43 -04:00
..
red_knot Gracefully handle errors in CLI (#12747) 2024-08-08 11:02:47 +00:00
red_knot_module_resolver Setup tracing and document tracing usage (#12730) 2024-08-08 06:28:40 +00:00
red_knot_python_semantic Setup tracing and document tracing usage (#12730) 2024-08-08 06:28:40 +00:00
red_knot_server Exit with an error if there are check failures (#12735) 2024-08-08 07:10:18 +00:00
red_knot_wasm [red-knot] Implement basic LSP server (#12624) 2024-08-06 11:27:30 +00:00
red_knot_workspace Gracefully handle errors in CLI (#12747) 2024-08-08 11:02:47 +00:00
ruff Exit with an error if there are check failures (#12735) 2024-08-08 07:10:18 +00:00
ruff_benchmark [red-knot] Rename workspace_root variables in the module resolver to src_root (#12697) 2024-08-05 23:07:18 +01:00
ruff_cache Fix cache key collisions for paths with separators (#12159) 2024-07-03 07:36:46 -05:00
ruff_db Setup tracing and document tracing usage (#12730) 2024-08-08 06:28:40 +00:00
ruff_dev Drop deprecated nursery rule group (#10172) 2024-06-27 13:44:11 +02:00
ruff_diagnostics Move sub-crates to workspace dependencies (#11407) 2024-05-13 14:37:50 +00:00
ruff_formatter Upgrade to Rust 1.80 (#12586) 2024-07-30 19:18:08 +00:00
ruff_index [red-knot] small efficiency improvements and bugfixes to use-def map building (#12373) 2024-07-18 09:24:58 -07:00
ruff_linter SIM110: any() is ~3x slower than the code it replaces (#12746) 2024-08-08 08:25:43 -04:00
ruff_macros Drop deprecated nursery rule group (#10172) 2024-06-27 13:44:11 +02:00
ruff_notebook [red-knot] Add notebook support (#12338) 2024-07-17 08:26:33 +00:00
ruff_python_ast Upgrade to Rust 1.80 (#12586) 2024-07-30 19:18:08 +00:00
ruff_python_ast_integration_tests Rename PreorderVisitor to SourceOrderVisitor (#11798) 2024-06-07 17:01:58 +00:00
ruff_python_codegen Use indentation consistently (#12293) 2024-07-12 14:08:56 +02:00
ruff_python_formatter Upgrade to Rust 1.80 (#12586) 2024-07-30 19:18:08 +00:00
ruff_python_index Enable token-based rules on source with syntax errors (#11950) 2024-07-02 08:57:46 +00:00
ruff_python_literal Remove some unused pub functions (#11576) 2024-05-28 09:56:51 -04:00
ruff_python_parser Upgrade to Rust 1.80 (#12586) 2024-07-30 19:18:08 +00:00
ruff_python_resolver chore(deps): update rust crate insta to v1.38.0 (#10701) 2024-04-01 15:44:30 +00:00
ruff_python_semantic Add a new Binding::is_unused method (#12729) 2024-08-07 11:17:56 +01:00
ruff_python_stdlib Add a new script to generate builtin module names (#12696) 2024-08-05 21:33:36 +01:00
ruff_python_trivia Mention that Cursor is based on rustc's implementation. (#12109) 2024-06-30 16:53:25 +01:00
ruff_python_trivia_integration_tests Build CommentRanges outside the parser (#11792) 2024-06-09 09:55:17 +00:00
ruff_server Use struct instead of type alias for workspace settings index (#12726) 2024-08-07 09:26:59 +00:00
ruff_source_file red-knot: source_text, line_index, and parsed_module queries (#11822) 2024-06-13 07:37:02 +00:00
ruff_text_size Upgrade to Rust 1.79 (#11875) 2024-06-17 07:15:10 +01:00
ruff_wasm Release Ruff 0.5.6 (#12629) 2024-08-02 17:35:14 +02:00
ruff_workspace Fix cache invalidation for nested pyproject.toml files (#12727) 2024-08-07 21:53:45 +02:00