-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench.js
43 lines (36 loc) · 948 Bytes
/
bench.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const { deepen } = require('./index.js')
const keywords = [
'a','b','c','d','e','f','g','h',
'i','j','k','l','m','n','o','p',
'q','r','s','t','u','v','w','x',
'y','z'
]
const columns = 10
const rows = 10
const size = 3
function rand(min, max) {
return Math.random() * (max - min) + min;
}
function build(){
const matrix = []
for(let i = 0; i < rows; i ++){
matrix[i] = []
for(let ii = 0; ii < rows; ii ++){
matrix[i][ii] = []
for(let iii = 0; iii < size; iii ++){
matrix[i][ii].push(keywords[parseInt(rand(0, 26))])
}
}
}
console.log(matrix)
return matrix
}
let cost = []
for(let i = 0; i < 1000; i++){
const matrix = build()
let t = new Date()
console.log(deepen(matrix))
cost.push(new Date() - t)
}
let average = (array) => array.reduce((a, b) => a + b) / array.length
console.log('cost avg', average(cost))