[Webkit-unassigned] [Bug 237385] New: let vs var performance
bugzilla-daemon at webkit.org
bugzilla-daemon at webkit.org
Wed Mar 2 11:33:28 PST 2022
https://bugs.webkit.org/show_bug.cgi?id=237385
Bug ID: 237385
Summary: let vs var performance
Product: WebKit
Version: Safari 15
Hardware: All
OS: All
Status: NEW
Severity: Normal
Priority: P2
Component: JavaScriptCore
Assignee: webkit-unassigned at lists.webkit.org
Reporter: jeremy.tellaa at gmail.com
I have built a very basic POC, and I found that looping when the loop is initialized with `let` instead of `var` is about seven times slower:
```
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<title>POC</title>
</head>
<body>
<div id="root"></div>
<script type="text/javascript">
const nb = 1000 * 1000 * 1000;
const t0 = performance.now();
for (var i = 0; i < nb; i++) { };
const t1 = performance.now();
for (let j = 0; j < nb; j++) { };
const t2 = performance.now();
const resVar = Math.floor(t1 - t0);
const resLet = Math.floor(t2 - t1);
res = `Looping ${nb} times with 'var' took ${resVar}ms.<br>Looping ${nb} times with 'let' took ${resLet}ms.`
document.getElementById('root').innerHTML = res;
</script>
</body>
</html>
```
--
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20220302/50b70f8d/attachment.htm>
More information about the webkit-unassigned
mailing list