-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Showing
4 changed files
with
87 additions
and
23 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,16 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | ||
<title>JSZip Performance</title> | ||
</head> | ||
<body> | ||
<script src="../../node_modules/benchmark/node_modules/lodash/lodash.js"></script> | ||
<script src="../../node_modules/benchmark/benchmark.js"></script> | ||
<script src="../../dist/jszip.js"></script> | ||
<script src="./perf.js"></script> | ||
<script> | ||
benchmark("arraybuffer"); | ||
</script> | ||
</body> | ||
</html> |
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 |
---|---|---|
@@ -1,26 +1,39 @@ | ||
"use strict"; | ||
|
||
module.exports = function (type) { | ||
const suite = new Benchmark.Suite(); | ||
(function (root, factory) { | ||
if (typeof module === "object" && module.exports) { | ||
module.exports = factory(); | ||
} else { | ||
root.benchmark = factory(); | ||
} | ||
}(typeof self !== "undefined" ? self : this, function () { | ||
return function (type) { | ||
return new Promise(resolve => { | ||
const suite = new Benchmark.Suite(); | ||
|
||
suite | ||
.add("generateAsync", { | ||
defer: true, | ||
async fn(deferred) { | ||
const zip = new JSZip(); | ||
suite | ||
.add(`${type} generateAsync`, { | ||
defer: true, | ||
async fn(deferred) { | ||
const zip = new JSZip(); | ||
|
||
for (let i = 0; i < 50; i++) { | ||
zip.file("file_" + i, "R0lGODdhBQAFAIACAAAAAP/eACwAAAAABQAFAAACCIwPkWerClIBADs=", { base64: true, date: new Date(1234123491011) }); | ||
} | ||
for (let i = 0; i < 50; i++) { | ||
zip.file("file_" + i, "R0lGODdhBQAFAIACAAAAAP/eACwAAAAABQAFAAACCIwPkWerClIBADs=", { base64: true, date: new Date(1234123491011) }); | ||
} | ||
|
||
await zip.generateAsync({ type }); | ||
deferred.resolve(); | ||
} | ||
}) | ||
.on("cycle", event => { | ||
// Output benchmark result by converting benchmark result to string | ||
console.log(String(event.target)); | ||
}) | ||
.on("complete", () => console.log("Benchmark complete")) | ||
.run({ "async": true }); | ||
}; | ||
await zip.generateAsync({ type }); | ||
deferred.resolve(); | ||
} | ||
}) | ||
.on("cycle", event => { | ||
// Output benchmark result by converting benchmark result to string | ||
console.log(String(event.target)); | ||
}) | ||
.on("complete", () => { | ||
console.log("Benchmark complete"); | ||
resolve(); | ||
}) | ||
.run({ "async": true }); | ||
}); | ||
}; | ||
})); |
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