-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(poseidon): add benchmarks and update conditional exports
re #238
- Loading branch information
Showing
58 changed files
with
711 additions
and
513 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,37 @@ | ||
import b from "benny" | ||
import { poseidon2 as _poseidon2 } from "poseidon-lite" | ||
import { poseidon as _poseidon } from "circomlibjs" | ||
import { poseidon2 } from "@zk-kit/poseidon" | ||
|
||
const name = "poseidon" | ||
|
||
export default async function run() { | ||
const numberOfHashes = 50 | ||
|
||
b.suite( | ||
name, | ||
|
||
b.add(`PoseidonLite - ${numberOfHashes} hashes`, () => { | ||
for (let i = 0; i < numberOfHashes; i += 1) { | ||
_poseidon2([1n, 2n]) | ||
} | ||
}), | ||
b.add(`CircomlibJS Poseidon - ${numberOfHashes} hashes`, () => { | ||
for (let i = 0; i < numberOfHashes; i += 1) { | ||
_poseidon([1n, 2n]) | ||
} | ||
}), | ||
b.add(`ZK-Kit Poseidon - ${numberOfHashes} hashes`, () => { | ||
for (let i = 0; i < numberOfHashes; i += 1) { | ||
poseidon2([1n, 2n]) | ||
} | ||
}), | ||
|
||
b.cycle(), | ||
b.complete(), | ||
|
||
b.save({ folder: "benchmarks/results", file: name, version: "1.0.0", details: true }), | ||
b.save({ folder: "benchmarks/results", file: name, format: "chart.html", details: true }), | ||
b.save({ folder: "benchmarks/results", file: name, format: "table.html", details: 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
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
File renamed without changes.
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,17 @@ | ||
import getConstants from "../getConstants" | ||
import poseidonBasic from "../poseidon-basic" | ||
import { C, M } from "./constants" | ||
|
||
const instance = poseidonBasic(1, getConstants(C, M)) | ||
|
||
/** | ||
* Calculate the poseidon hash of 1 input. | ||
* The constants used in this implementation are encoded as base64 strings to save space, | ||
* and are converted into bigints when this module is imported, to save time when hashes are calculated. | ||
* @param inputs List of values to be hashed. | ||
* @param cacheConstants Boolean to allow constants to be cached. | ||
* @returns The Poseidon hash. | ||
*/ | ||
export default function poseidon(inputs: (bigint | string | number)[]) { | ||
return instance([0n, ...inputs.map(BigInt)])[0] | ||
} |
File renamed without changes.
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,17 @@ | ||
import getConstants from "../getConstants" | ||
import poseidonBasic from "../poseidon-basic" | ||
import { C, M } from "./constants" | ||
|
||
const instance = poseidonBasic(10, getConstants(C, M)) | ||
|
||
/** | ||
* Calculate the poseidon hash of 10 inputs. | ||
* The constants used in this implementation are encoded as base64 strings to save space, | ||
* and are converted into bigints when this module is imported, to save time when hashes are calculated. | ||
* @param inputs List of values to be hashed. | ||
* @param cacheConstants Boolean to allow constants to be cached. | ||
* @returns The Poseidon hash. | ||
*/ | ||
export default function poseidon(inputs: (bigint | string | number)[]) { | ||
return instance([0n, ...inputs.map(BigInt)])[0] | ||
} |
File renamed without changes.
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,17 @@ | ||
import getConstants from "../getConstants" | ||
import poseidonBasic from "../poseidon-basic" | ||
import { C, M } from "./constants" | ||
|
||
const instance = poseidonBasic(11, getConstants(C, M)) | ||
|
||
/** | ||
* Calculate the poseidon hash of 11 inputs. | ||
* The constants used in this implementation are encoded as base64 strings to save space, | ||
* and are converted into bigints when this module is imported, to save time when hashes are calculated. | ||
* @param inputs List of values to be hashed. | ||
* @param cacheConstants Boolean to allow constants to be cached. | ||
* @returns The Poseidon hash. | ||
*/ | ||
export default function poseidon(inputs: (bigint | string | number)[]) { | ||
return instance([0n, ...inputs.map(BigInt)])[0] | ||
} |
File renamed without changes.
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,17 @@ | ||
import getConstants from "../getConstants" | ||
import poseidonBasic from "../poseidon-basic" | ||
import { C, M } from "./constants" | ||
|
||
const instance = poseidonBasic(12, getConstants(C, M)) | ||
|
||
/** | ||
* Calculate the poseidon hash of 12 inputs. | ||
* The constants used in this implementation are encoded as base64 strings to save space, | ||
* and are converted into bigints when this module is imported, to save time when hashes are calculated. | ||
* @param inputs List of values to be hashed. | ||
* @param cacheConstants Boolean to allow constants to be cached. | ||
* @returns The Poseidon hash. | ||
*/ | ||
export default function poseidon(inputs: (bigint | string | number)[]) { | ||
return instance([0n, ...inputs.map(BigInt)])[0] | ||
} |
File renamed without changes.
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,17 @@ | ||
import getConstants from "../getConstants" | ||
import poseidonBasic from "../poseidon-basic" | ||
import { C, M } from "./constants" | ||
|
||
const instance = poseidonBasic(13, getConstants(C, M)) | ||
|
||
/** | ||
* Calculate the poseidon hash of 13 inputs. | ||
* The constants used in this implementation are encoded as base64 strings to save space, | ||
* and are converted into bigints when this module is imported, to save time when hashes are calculated. | ||
* @param inputs List of values to be hashed. | ||
* @param cacheConstants Boolean to allow constants to be cached. | ||
* @returns The Poseidon hash. | ||
*/ | ||
export default function poseidon(inputs: (bigint | string | number)[]) { | ||
return instance([0n, ...inputs.map(BigInt)])[0] | ||
} |
File renamed without changes.
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,17 @@ | ||
import getConstants from "../getConstants" | ||
import poseidonBasic from "../poseidon-basic" | ||
import { C, M } from "./constants" | ||
|
||
const instance = poseidonBasic(14, getConstants(C, M)) | ||
|
||
/** | ||
* Calculate the poseidon hash of 14 inputs. | ||
* The constants used in this implementation are encoded as base64 strings to save space, | ||
* and are converted into bigints when this module is imported, to save time when hashes are calculated. | ||
* @param inputs List of values to be hashed. | ||
* @param cacheConstants Boolean to allow constants to be cached. | ||
* @returns The Poseidon hash. | ||
*/ | ||
export default function poseidon(inputs: (bigint | string | number)[]) { | ||
return instance([0n, ...inputs.map(BigInt)])[0] | ||
} |
File renamed without changes.
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,17 @@ | ||
import getConstants from "../getConstants" | ||
import poseidonBasic from "../poseidon-basic" | ||
import { C, M } from "./constants" | ||
|
||
const instance = poseidonBasic(15, getConstants(C, M)) | ||
|
||
/** | ||
* Calculate the poseidon hash of 15 inputs. | ||
* The constants used in this implementation are encoded as base64 strings to save space, | ||
* and are converted into bigints when this module is imported, to save time when hashes are calculated. | ||
* @param inputs List of values to be hashed. | ||
* @param cacheConstants Boolean to allow constants to be cached. | ||
* @returns The Poseidon hash. | ||
*/ | ||
export default function poseidon(inputs: (bigint | string | number)[]) { | ||
return instance([0n, ...inputs.map(BigInt)])[0] | ||
} |
File renamed without changes.
Oops, something went wrong.