GithubHelp home page GithubHelp logo

Comments (3)

1000i100 avatar 1000i100 commented on August 18, 2024

My small bench for 1 000 000 sha256 :
2021-04 latest version :
TorBrowser : 51.7 s
Firefox : 46.3 s
Chromium : 23.1 s
Nodejs native crypto : 2.6 s
Nodejs js-sha256 : 1.8 s

Browser native :

const array = new Uint8Array(32);
async function bench() {
	const start = Date.now();
	for(let x = 1;x < 1000000 ; x++) {
		await crypto.subtle.digest('SHA-256', array);
	}
	const end = Date.now();
	console.log(end-start);
}
bench();

Nodejs native crypto :

import crypto from 'crypto';
const array = new Uint8Array(32);
async function bench() {
	const start = Date.now();
	for(let x = 1;x < 1000000 ; x++) {
		const sha = crypto.createHash('sha256')
		sha.update(array);
		sha.digest();
	}
	const end = Date.now();
	console.log(end-start);
}
bench();

Nodejs js-sha256 :

import sha256 from 'js-sha256';
const array = new Uint8Array(32);
async function bench() {
	const start = Date.now();
	for(let x = 1;x < 1000000 ; x++) {
		sha256(array);
	}
	const end = Date.now();
	console.log(end-start);
}
bench();

from js-sha256.

1000i100 avatar 1000i100 commented on August 18, 2024

Dummy (no sha256 computing) : 0,2s

import jsSha256 from 'js-sha256';
const array = new Uint8Array(32);
async function bench() {
	const start = Date.now();
	let last;
	for(let x = 1;x < 10_000_000 ; x++) {
		fillArrayWithInt(array,x);
		//last = await jsSha256().update(array).digest();
	}
	const end = Date.now();
	console.log(end-start);
	console.log(array);
	console.log(last);
}
bench();

function fillArrayWithInt(array,int){
	for(let i =0;int>0;i++){
		array[i] = int%256;
		int = Math.trunc(int/256);
	}
}

node js-sha256 : 17s

firefox js-sha256 : 107s

import jsSha256 from 'js-sha256';
const array = new Uint8Array(32);
async function bench() {
	const start = Date.now();
	let last;
	for(let x = 1;x < 10_000_000 ; x++) {
		fillArrayWithInt(array,x);
		last = await jsSha256.update(array).digest();
	}
	const end = Date.now();
	console.log(end-start);
	console.log(array);
	console.log(last);
}
bench();

function fillArrayWithInt(array,int){
	for(let i =0;int>0;i++){
		array[i] = int%256;
		int = Math.trunc(int/256);
	}
}

native nodejs crypto : 27s

import crypto from 'crypto';
const array = new Uint8Array(32);
async function bench() {
	const start = Date.now();
	let last;
	for(let x = 1;x < 10_000_000 ; x++) {
		fillArrayWithInt(array,x);
		last = await crypto.createHash('sha256').update(array).digest();
	}
	const end = Date.now();
	console.log(end-start);
	console.log(array);
	console.log(last);
}
bench();

function fillArrayWithInt(array,int){
	for(let i =0;int>0;i++){
		array[i] = int%256;
		int = Math.trunc(int/256);
	}
}

Firefox native webcrypto : 485s

const array = new Uint8Array(32);
async function bench() {
	const start = Date.now();
	let last;
	for(let x = 1;x < 10_000_000 ; x++) {
		fillArrayWithInt(array,x);
		last = await crypto.subtle.digest('SHA-256', array);
	}
	const end = Date.now();
	console.log(end-start);
	console.log(array);
	console.log(last);
}
bench();

function fillArrayWithInt(array,int){
	for(let i =0;int>0;i++){
		array[i] = int%256;
		int = Math.trunc(int/256);
	}
}

from js-sha256.

emn178 avatar emn178 commented on August 18, 2024

I also added benchmark in README by using jsPerf.

from js-sha256.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.