-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(benchmark): migrate to Deno.bench
- Loading branch information
Showing
7 changed files
with
102 additions
and
308 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,182 +1,131 @@ | ||
import { bench, runBenchmarks } from "../dev_deps.ts"; | ||
import { AES as GodCryptoAES } from "https://deno.land/x/god_crypto@v1.4.11/aes.ts"; | ||
import { Aes } from "../aes.ts"; | ||
import { Cbc, Cfb, Ctr, Ecb, Ofb } from "../block-modes.ts"; | ||
import { AES as GodCryptoAES } from "https://deno.land/x/god_crypto@v1.4.9/aes.ts"; | ||
import { args } from "./utils/benchmarkArgs.ts"; | ||
|
||
const { runs: _runs, ...opts } = args; | ||
const runs = _runs || 25; | ||
|
||
const key = new Uint8Array(16); | ||
const iv = new Uint8Array(Aes.BLOCK_SIZE); | ||
const data = new Uint8Array(1024 * 1024 * 2); | ||
|
||
bench({ | ||
Deno.bench({ | ||
name: "AES-128-ECB 2MiB Encrypt", | ||
runs, | ||
func(b) { | ||
fn() { | ||
const cipher = new Ecb(Aes, key); | ||
b.start(); | ||
cipher.encrypt(data); | ||
b.stop(); | ||
}, | ||
}); | ||
|
||
bench({ | ||
Deno.bench({ | ||
name: "AES-128-ECB 2MiB Decrypt", | ||
runs, | ||
func(b) { | ||
fn() { | ||
const cipher = new Ecb(Aes, key); | ||
b.start(); | ||
cipher.decrypt(data); | ||
b.stop(); | ||
}, | ||
}); | ||
|
||
bench({ | ||
Deno.bench({ | ||
name: "AES-128-CBC 2MiB Encrypt", | ||
runs, | ||
func(b) { | ||
fn() { | ||
const cipher = new Cbc(Aes, key, iv); | ||
b.start(); | ||
cipher.encrypt(data); | ||
b.stop(); | ||
}, | ||
}); | ||
|
||
bench({ | ||
Deno.bench({ | ||
name: "AES-128-CBC 2MiB Decrypt", | ||
runs, | ||
func(b) { | ||
fn() { | ||
const cipher = new Cbc(Aes, key, iv); | ||
b.start(); | ||
cipher.decrypt(data); | ||
b.stop(); | ||
}, | ||
}); | ||
|
||
bench({ | ||
Deno.bench({ | ||
name: "AES-128-CFB 2MiB Encrypt", | ||
runs, | ||
func(b) { | ||
fn() { | ||
const cipher = new Cfb(Aes, key, iv); | ||
b.start(); | ||
cipher.encrypt(data); | ||
b.stop(); | ||
}, | ||
}); | ||
|
||
bench({ | ||
Deno.bench({ | ||
name: "AES-128-CFB 2MiB Decrypt", | ||
runs, | ||
func(b) { | ||
fn() { | ||
const cipher = new Cfb(Aes, key, iv); | ||
b.start(); | ||
cipher.decrypt(data); | ||
b.stop(); | ||
}, | ||
}); | ||
|
||
bench({ | ||
Deno.bench({ | ||
name: "AES-128-OFB 2MiB Encrypt/Decrypt", | ||
runs, | ||
func(b) { | ||
fn() { | ||
const cipher = new Ofb(Aes, key, iv); | ||
b.start(); | ||
cipher.encrypt(data); | ||
b.stop(); | ||
}, | ||
}); | ||
|
||
bench({ | ||
Deno.bench({ | ||
name: "AES-128-CTR 2MiB Encrypt/Decrypt", | ||
runs, | ||
func(b) { | ||
fn() { | ||
const cipher = new Ctr(Aes, key, iv); | ||
b.start(); | ||
cipher.encrypt(data); | ||
b.stop(); | ||
}, | ||
}); | ||
|
||
bench({ | ||
Deno.bench({ | ||
name: "AES-128-ECB (GodCrypto) 2MiB Encrypt", | ||
runs, | ||
async func(b) { | ||
async fn() { | ||
const cipher = new GodCryptoAES(key, { mode: "ecb" }); | ||
b.start(); | ||
await cipher.encrypt(data); | ||
b.stop(); | ||
}, | ||
}); | ||
|
||
bench({ | ||
Deno.bench({ | ||
name: "AES-128-ECB (GodCrypto) 2MiB Decrypt", | ||
runs, | ||
async func(b) { | ||
async fn() { | ||
const cipher = new GodCryptoAES(key, { mode: "ecb" }); | ||
b.start(); | ||
await cipher.decrypt(data); | ||
b.stop(); | ||
}, | ||
}); | ||
|
||
bench({ | ||
Deno.bench({ | ||
name: "AES-128-CBC (GodCrypto) 2MiB Encrypt", | ||
runs, | ||
async func(b) { | ||
async fn() { | ||
const cipher = new GodCryptoAES(key, { | ||
mode: "cbc", | ||
iv, | ||
}); | ||
b.start(); | ||
await cipher.encrypt(data); | ||
b.stop(); | ||
}, | ||
}); | ||
|
||
bench({ | ||
Deno.bench({ | ||
name: "AES-128-CBC (GodCrypto) 2MiB Decrypt", | ||
runs, | ||
async func(b) { | ||
async fn() { | ||
const cipher = new GodCryptoAES(key, { | ||
mode: "cbc", | ||
iv, | ||
}); | ||
b.start(); | ||
await cipher.decrypt(data); | ||
b.stop(); | ||
}, | ||
}); | ||
|
||
bench({ | ||
Deno.bench({ | ||
name: "AES-128-CFB (GodCrypto) 2MiB Encrypt", | ||
runs, | ||
async func(b) { | ||
async fn() { | ||
const cipher = new GodCryptoAES(key, { | ||
mode: "cfb", | ||
iv, | ||
}); | ||
b.start(); | ||
await cipher.encrypt(data); | ||
b.stop(); | ||
}, | ||
}); | ||
|
||
bench({ | ||
Deno.bench({ | ||
name: "AES-128-CFB (GodCrypto) 2MiB Decrypt", | ||
runs, | ||
async func(b) { | ||
async fn() { | ||
const cipher = new GodCryptoAES(key, { | ||
mode: "cfb", | ||
iv, | ||
}); | ||
b.start(); | ||
await cipher.decrypt(data); | ||
b.stop(); | ||
}, | ||
}); | ||
|
||
if (import.meta.main) { | ||
runBenchmarks(opts); | ||
} |
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,11 +1,5 @@ | ||
import { runBenchmarks } from "../dev_deps.ts"; | ||
import { args } from "./utils/benchmarkArgs.ts"; | ||
import "./aes.ts"; | ||
import "./blowfish.ts"; | ||
import "./cast5.ts"; | ||
import "./des.ts"; | ||
import "./tdes.ts"; | ||
|
||
const { runs: _, ...opts } = args; | ||
|
||
runBenchmarks(opts); |
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,117 +1,79 @@ | ||
import { bench, runBenchmarks } from "../dev_deps.ts"; | ||
import { Blowfish } from "../blowfish.ts"; | ||
import { Cbc, Cfb, Ctr, Ecb, Ofb } from "../block-modes.ts"; | ||
import { args } from "./utils/benchmarkArgs.ts"; | ||
|
||
const { runs: _runs, ...opts } = args; | ||
const runs = _runs || 25; | ||
import { Blowfish } from "../blowfish.ts"; | ||
|
||
const key = new Uint8Array(8); | ||
const iv = new Uint8Array(Blowfish.BLOCK_SIZE); | ||
const data = new Uint8Array(1024 * 1024 * 2); | ||
|
||
bench({ | ||
Deno.bench({ | ||
name: "Blowfish-ECB 2MiB Encrypt", | ||
runs, | ||
func(b) { | ||
fn() { | ||
const cipher = new Ecb(Blowfish, key); | ||
b.start(); | ||
cipher.encrypt(data); | ||
b.stop(); | ||
}, | ||
}); | ||
|
||
bench({ | ||
Deno.bench({ | ||
name: "Blowfish-ECB 2MiB Encrypt", | ||
runs, | ||
func(b) { | ||
fn() { | ||
const cipher = new Ecb(Blowfish, key); | ||
b.start(); | ||
cipher.encrypt(data); | ||
b.stop(); | ||
}, | ||
}); | ||
|
||
bench({ | ||
Deno.bench({ | ||
name: "Blowfish-ECB 2MiB Decrypt", | ||
runs, | ||
func(b) { | ||
fn() { | ||
const cipher = new Ecb(Blowfish, key); | ||
b.start(); | ||
cipher.decrypt(data); | ||
b.stop(); | ||
}, | ||
}); | ||
|
||
bench({ | ||
Deno.bench({ | ||
name: "Blowfish-CBC 2MiB Encrypt", | ||
runs, | ||
func(b) { | ||
fn() { | ||
const cipher = new Cbc(Blowfish, key, iv); | ||
|
||
b.start(); | ||
cipher.encrypt(data); | ||
b.stop(); | ||
}, | ||
}); | ||
|
||
bench({ | ||
Deno.bench({ | ||
name: "Blowfish-CBC 2MiB Decrypt", | ||
runs, | ||
func(b) { | ||
fn() { | ||
const bf = new Cbc(Blowfish, key, iv); | ||
b.start(); | ||
bf.decrypt(data); | ||
b.stop(); | ||
}, | ||
}); | ||
|
||
bench({ | ||
Deno.bench({ | ||
name: "Blowfish-CFB 2MiB Encrypt", | ||
runs, | ||
func(b) { | ||
fn() { | ||
const cipher = new Cfb(Blowfish, key, iv); | ||
|
||
b.start(); | ||
cipher.encrypt(data); | ||
b.stop(); | ||
}, | ||
}); | ||
|
||
bench({ | ||
Deno.bench({ | ||
name: "Blowfish-CFB 2MiB Decrypt", | ||
runs, | ||
func(b) { | ||
fn() { | ||
const cipher = new Cfb(Blowfish, key, iv); | ||
b.start(); | ||
cipher.decrypt(data); | ||
b.stop(); | ||
}, | ||
}); | ||
|
||
bench({ | ||
Deno.bench({ | ||
// Encryption and decryption are the same | ||
name: "Blowfish-OFB 2MiB Encrypt/Decrypt", | ||
runs, | ||
func(b) { | ||
fn() { | ||
const cipher = new Ofb(Blowfish, key, iv); | ||
b.start(); | ||
cipher.encrypt(data); | ||
b.stop(); | ||
}, | ||
}); | ||
|
||
bench({ | ||
Deno.bench({ | ||
name: "Blowfish-CTR 2MiB Encrypt/Decrypt", | ||
runs, | ||
func(b) { | ||
fn() { | ||
const cipher = new Ctr(Blowfish, key, iv); | ||
b.start(); | ||
cipher.encrypt(data); | ||
b.stop(); | ||
}, | ||
}); | ||
|
||
if (import.meta.main) { | ||
runBenchmarks(opts); | ||
} |
Oops, something went wrong.