This repository has been archived on 2023-04-09. You can view files and clone it, but cannot push or open issues or pull requests.
chainsafe-bls/test/unit/multithread/naive/utils.ts

24 lines
747 B
TypeScript

import os from "os";
import {IBls} from "../../../../src";
import {BlsMultiThreadNaive} from "./index";
export async function warmUpWorkers(bls: IBls, pool: BlsMultiThreadNaive): Promise<void> {
const msg = Buffer.alloc(32, 1);
const sk = bls.SecretKey.fromKeygen(Buffer.alloc(32, 1));
const pk = sk.toPublicKey();
const sig = sk.sign(msg);
await Promise.all(Array.from({length: os.cpus().length}, (_, i) => i).map(() => pool.verify(pk, msg, sig)));
}
export function chunkify<T>(arr: T[], chunkCount: number): T[][] {
const chunkSize = Math.round(arr.length / chunkCount);
const arrArr: T[][] = [];
for (let i = 0, j = arr.length; i < j; i += chunkSize) {
arrArr.push(arr.slice(i, i + chunkSize));
}
return arrArr;
}