Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
python len vs cache
(version: 2)
Comparing performance of:
use len built-in vs use variable to cache size
Created:
one year ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src='https://cdn.jsdelivr.net/pyodide/v0.26.3/full/pyodide.js'></script>
Script Preparation code:
async function globalMeasureThatScriptPrepareFunction() { window.globalPyodide = await loadPyodide(); await globalPyodide.runPython(` def test_len(n): arr = [0] * n for i in range(n): arr[i] = i return len(arr) def test_cache(n): arr = [0] * n l = 0 for i in range(n): arr[i] = i l += 1 return l def run(fct, n): for i in range(n): fct(n) `); }
Tests:
use len built-in
window.globalPyodide.runPython(` run(test_len, 1000) `);
use variable to cache size
window.globalPyodide.runPython(` run(test_cache, 1000) `);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
use len built-in
use variable to cache size
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser/OS:
Chrome 131 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
use len built-in
21.8 Ops/sec
use variable to cache size
12.5 Ops/sec
Related benchmarks:
Test samples
Test samples
reverse
**2 vs * vs Math.Pow for equated number
Test performance of deep coping frok frok
object readings
for-in vs for-of-entires
loop vs raw fn
single for loop vs multiple for loops for iterating over arrays
Comments
Confirm delete:
Do you really want to delete benchmark?