summaryrefslogtreecommitdiff
path: root/cli/bench/cache_api.js
diff options
context:
space:
mode:
authorSatya Rohith <me@satyarohith.com>2022-09-28 17:41:12 +0530
committerGitHub <noreply@github.com>2022-09-28 17:41:12 +0530
commitb312279e58e51520a38e51cca317a09cdadd7cb4 (patch)
treea0c6f432042ba25b569c151bbe59f1e721788d0c /cli/bench/cache_api.js
parent1156f726a92d3d3985e591327c7526cd3e2b0473 (diff)
feat: implement Web Cache API (#15829)
Diffstat (limited to 'cli/bench/cache_api.js')
-rw-r--r--cli/bench/cache_api.js56
1 files changed, 56 insertions, 0 deletions
diff --git a/cli/bench/cache_api.js b/cli/bench/cache_api.js
new file mode 100644
index 000000000..3e059e80a
--- /dev/null
+++ b/cli/bench/cache_api.js
@@ -0,0 +1,56 @@
+// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
+
+const cacheName = "cache-v1";
+const cache = await caches.open(cacheName);
+const req = "https://deno.com";
+
+Deno.bench(
+ `cache_storage_open`,
+ async () => {
+ await caches.open("cache-v2");
+ },
+);
+
+Deno.bench(
+ `cache_storage_has`,
+ async () => {
+ await caches.has("cache-v2");
+ },
+);
+
+Deno.bench(
+ `cache_storage_delete`,
+ async () => {
+ await caches.delete("cache-v2");
+ },
+);
+
+// 100 bytes.
+const loremIpsum =
+ `Lorem ipsum dolor sit amet, consectetur adipiscing…es ligula in libero. Sed dignissim lacinia nunc. `;
+let body;
+for (let index = 1; index <= 110; index++) {
+ body += loremIpsum;
+}
+
+Deno.bench(
+ `cache_put_body_${Math.floor(body.length / 1024)}_KiB`,
+ async () => {
+ await cache.put(req, new Response(body));
+ },
+);
+
+Deno.bench("cache_put_no_body", async () => {
+ await cache.put(
+ "https://deno.land/redirect",
+ Response.redirect("https://deno.com"),
+ );
+});
+
+Deno.bench("cache_match", async () => {
+ await cache.match(req);
+});
+
+Deno.bench("cache_delete", async () => {
+ await cache.delete(req);
+});