Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

date-format: Add result hashing to prevent DCE #60

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion SunSpider/date-format-tofte.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,21 +291,27 @@ Date.prototype.formatDate = function (input,time) {

function run() {
var date = new Date("1/1/2007 1:11:11");
var resultHash = 0x1a2b3c4d;

for (i = 0; i < 500; ++i) {
var shortFormat = date.formatDate("Y-m-d");
var longFormat = date.formatDate("l, F d, Y g:i:s A");
date.setTime(date.getTime() + 84266956);
// Assuming only ascii output.
resultHash ^= shortFormat.charCodeAt(6) | shortFormat.charCodeAt(8) << 8;
resultHash ^= longFormat.charCodeAt(10) << 16 | longFormat.charCodeAt(11) << 24;
}

// FIXME: Find a way to validate this test.
// https://bugs.webkit.org/show_bug.cgi?id=114849
return resultHash;
}


class Benchmark {
runIteration() {
this.resultHash = 0x1a2b3c4d;
for (let i = 0; i < 8; ++i)
run();
this.resultHash ^= run();
}
}
8 changes: 7 additions & 1 deletion SunSpider/date-format-xparb.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,21 +410,27 @@ Date.patterns = {

function run() {
var date = new Date("1/1/2007 1:11:11");
var resultHash = 0x1a2b3c4d;

for (i = 0; i < 4000; ++i) {
var shortFormat = date.dateFormat("Y-m-d");
var longFormat = date.dateFormat("l, F d, Y g:i:s A");
date.setTime(date.getTime() + 84266956);
// Assuming only ascii output.
resultHash ^= shortFormat.charCodeAt(6) | shortFormat.charCodeAt(8) << 8;
resultHash ^= longFormat.charCodeAt(10) << 16 | longFormat.charCodeAt(11) << 24;
}

// FIXME: Find a way to validate this test.
// https://bugs.webkit.org/show_bug.cgi?id=114849
return resultHash;
}


class Benchmark {
runIteration() {
this.resultHash = 0x1a2b3c4d;
for (let i = 0; i < 8; ++i)
run();
this.resultHash ^= run();
}
}