Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add opt to use existing loc obj in weekdays/months (#877)
* Add opt to use existing loc obj in weekdays/months * Added info benchmarks
- Loading branch information
1 parent
8899e9f
commit 3d74e60
Showing
6 changed files
with
215 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import dateTimeSuites from "./datetime"; | ||
import infoSuites from "./info"; | ||
|
||
const allSuites = [...dateTimeSuites, ...infoSuites]; | ||
|
||
async function runAllSuites() { | ||
for (const runSuite of allSuites) { | ||
await runSuite(); | ||
} | ||
} | ||
|
||
runAllSuites(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* eslint import/no-extraneous-dependencies: off */ | ||
/* eslint no-console: off */ | ||
import Benchmark from "benchmark"; | ||
import Info from "../src/info"; | ||
import Locale from "../src/impl/locale.js"; | ||
|
||
function runWeekdaysSuite() { | ||
return new Promise((resolve, reject) => { | ||
const locale = Locale.create(null, null, null); | ||
|
||
new Benchmark.Suite() | ||
.add("Info.weekdays with existing locale", () => { | ||
Info.weekdays("long", { locObj: locale }); | ||
}) | ||
.add("Info.weekdays", () => { | ||
Info.weekdays("long"); | ||
}) | ||
.on("cycle", event => { | ||
console.log(String(event.target)); | ||
}) | ||
// eslint-disable-next-line func-names | ||
.on("complete", function() { | ||
console.log("Fastest is " + this.filter("fastest").map("name")); | ||
resolve(); | ||
}) | ||
.on("error", function() { | ||
reject(this.error); | ||
}) | ||
.run(); | ||
}); | ||
} | ||
|
||
function runWeekdaysFormatSuite() { | ||
return new Promise((resolve, reject) => { | ||
const locale = Locale.create(null, null, null); | ||
|
||
new Benchmark.Suite() | ||
.add("Info.weekdaysFormat with existing locale", () => { | ||
Info.weekdaysFormat("long", { locObj: locale }); | ||
}) | ||
.add("Info.weekdaysFormat", () => { | ||
Info.weekdaysFormat("long"); | ||
}) | ||
.on("cycle", event => { | ||
console.log(String(event.target)); | ||
}) | ||
// eslint-disable-next-line func-names | ||
.on("complete", function() { | ||
console.log("Fastest is " + this.filter("fastest").map("name")); | ||
resolve(); | ||
}) | ||
.on("error", function() { | ||
reject(this.error); | ||
}) | ||
.run(); | ||
}); | ||
} | ||
|
||
function runMonthsSuite() { | ||
return new Promise((resolve, reject) => { | ||
const locale = Locale.create(null, null, null); | ||
new Benchmark.Suite() | ||
.add("Info.months with existing locale", () => { | ||
Info.months("long", { locObj: locale }); | ||
}) | ||
.add("Info.months", () => { | ||
Info.months("long"); | ||
}) | ||
.on("cycle", event => { | ||
console.log(String(event.target)); | ||
}) | ||
// eslint-disable-next-line func-names | ||
.on("complete", function() { | ||
console.log("Fastest is " + this.filter("fastest").map("name")); | ||
resolve(); | ||
}) | ||
.on("error", function() { | ||
reject(this.error); | ||
}) | ||
.run(); | ||
}); | ||
} | ||
|
||
function runMonthsFormatSuite() { | ||
return new Promise((resolve, reject) => { | ||
const locale = Locale.create(null, null, null); | ||
|
||
new Benchmark.Suite() | ||
.add("Info.monthsFormat with existing locale", () => { | ||
Info.monthsFormat("long", { locObj: locale }); | ||
}) | ||
.add("Info.monthsFormat", () => { | ||
Info.monthsFormat("long"); | ||
}) | ||
.on("cycle", event => { | ||
console.log(String(event.target)); | ||
}) | ||
// eslint-disable-next-line func-names | ||
.on("complete", function() { | ||
console.log("Fastest is " + this.filter("fastest").map("name")); | ||
resolve(); | ||
}) | ||
.on("error", function() { | ||
reject(this.error); | ||
}) | ||
.run(); | ||
}); | ||
} | ||
|
||
const allSuites = [runMonthsSuite, runMonthsFormatSuite, runWeekdaysSuite, runWeekdaysFormatSuite]; | ||
|
||
export default allSuites; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters