Skip to content

Instantly share code, notes, and snippets.

@grahamannett
Created April 11, 2025 01:16
Show Gist options
  • Select an option

  • Save grahamannett/11a27ae8a14cab59266efb235ade6967 to your computer and use it in GitHub Desktop.

Select an option

Save grahamannett/11a27ae8a14cab59266efb235ade6967 to your computer and use it in GitHub Desktop.
cache getenv
❯ python -m timeit --setup "import os, functools; fn = functools.cache(lambda : os.getenv('PATH'))" -- "fn()" && python -m timeit --setup "import os; fn = lambda : os.getenv('PATH')" -- "fn()"
20000000 loops, best of 5: 19.9 nsec per loop
1000000 loops, best of 5: 342 nsec per loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment