-
Notifications
You must be signed in to change notification settings - Fork 48
Open
Description
I mean pattern matching is cool when it's a core language feature, but...
Test Code
const { matches } = require('z')
const zCompress = numbers => matches(numbers)(
(x, y, xs) => x === y
? zCompress([x].concat(xs))
: [x].concat(zCompress([y].concat(xs))),
(x, xs) => x // stopping condition
)
const jsCompress = numbers => numbers.filter((n, i) => n !== numbers[i - 1])
const input = [1, 1, 2, 3, 4, 4, 4]
const count = 100000
function time(fn) {
const start = Date.now()
for (let i = 0; i < count; i++) fn(input)
return Date.now() - start
}
const zTime = time(zCompress)
const jsTime = time(jsCompress)
console.log('z: ', zTime + ' ms')
console.log('js: ', jsTime + ' ms')
console.log(`z took ${zTime / jsTime} times longer`)
Results
MacBook Pro Mid 2014, macOS 10.15.5. Node 12.16.2.
$ node index.js
z: 12560 ms
js: 23 ms
z took 546.0869565217391 times longer
bas080
Metadata
Metadata
Assignees
Labels
No labels