-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2a9a906
commit 5209d85
Showing
3 changed files
with
38 additions
and
0 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
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,35 @@ | ||
const { readFileSync } = require("fs"); | ||
const { join } = require("path"); | ||
|
||
const { Format, decode, encode } = require("../source"); | ||
|
||
const iterations = 1000; | ||
|
||
const path = join(__dirname, "..", "test"); | ||
|
||
const webp = readFileSync(join(path, "512x512.webp")); | ||
|
||
const rgba = { | ||
data: readFileSync(join(path, "512x512.rgba")), | ||
format: Format.rgba, | ||
height: 512, | ||
width: 512 | ||
}; | ||
|
||
const benchmark = async (label, method, ...parameters) => { | ||
const start = Date.now(); | ||
for (let i = 0; i < iterations; i++) { | ||
await method(...parameters); // eslint-disable-line no-await-in-loop | ||
} | ||
console.log(`${label}: ${((Date.now() - start) / iterations).toFixed(2)}ms`); | ||
}; | ||
|
||
(async () => { | ||
for (const parameters of [ | ||
["WebP => RGBA", decode, webp, Format.rgba], | ||
["WebP => YUV ", decode, webp, Format.yuv], | ||
["RGBA => WebP", encode, rgba, 90] | ||
]) { | ||
await benchmark(...parameters); // eslint-disable-line no-await-in-loop | ||
} | ||
})(); |