Skip to content

Instantly share code, notes, and snippets.

@turicas
Created April 10, 2025 00:14
Show Gist options
  • Save turicas/f28c110d931c437f5b952040ec2c1da1 to your computer and use it in GitHub Desktop.
Save turicas/f28c110d931c437f5b952040ec2c1da1 to your computer and use it in GitHub Desktop.
Python tuple creation from list comprehesion is faster than from generator expression
#!/bin/bash
python -m timeit 'tuple(n for n in range(100))'
# Result: 100000 loops, best of 5: 2.09 usec per loop
python -m timeit 'tuple([n for n in range(100)])'
# Result: 200000 loops, best of 5: 1.13 usec per loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment