https://www.npmjs.com/package/object-hash
Https://www.npmjs.com/package/object-hash
var hash = require('object-hash');
hash({foo: 'bar'}) // => '67b69634f9880a282c14a0f0cb7ba20cf5d677e9'
- What is the maximum input object size?
- Is this a slow and expensive operation?
更多回答
A hash is not unique. That's impossible.
哈希不是唯一的。那怎么可能。
'Expensive' is subjective. You can see how expensive with a simple loop. Interpreted Javascript running in a browser calculates them very slowly compared to compiled languages. In a compiled language, on a modern CPU, you can calculate a sha256 64 byte block in about a microsecond. They have to be calculated serially, so 600 bytes takes 10 rounds. There's a theoretical limit to the size of the input of sha256 of 2^64 - 1 bits. I think its more for sha384 sha512 etc.
“昂贵”是主观的。您可以看到使用一个简单的循环是多么昂贵。与编译语言相比,在浏览器中运行的解释脚本计算它们非常慢。在编译语言中,在现代CPU上,您可以在大约一微秒内计算出一个sha256 64字节块。它们必须按顺序计算,因此600字节需要10轮。2^64-1位的sha256的输入大小在理论上是有限制的。我觉得sha384、sha512等的比较多。
优秀答案推荐
1- Object sizes depend on the platform. For example Chrome (V8) doesn't support more than 2GB of object in memory. https://bugs.chromium.org/p/v8/issues/detail?id=847
1-对象大小取决于平台。例如,Chrome(V8)不支持内存中超过2 GB的对象。Https://bugs.chromium.org/p/v8/issues/detail?id=847
2- The function is synchronous and I would assume each algorithm will result in a different time performance. You can surround your code with console.time
to measure the time and see if that fits your needs.
2-函数是同步的,我假设每个算法都会产生不同的时间性能。您可以在您的代码中使用console.time来测量时间,看看这是否符合您的需求。
console.time('hash')
hash({foo: 'bar'})
console.timeEnd('hash')
更多回答
我是一名优秀的程序员,十分优秀!