-
Notifications
You must be signed in to change notification settings - Fork 3
/
benchmark.js
60 lines (52 loc) · 1.4 KB
/
benchmark.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
'use strict'
const {Suite} = require('benchmark')
const solve = require('.')
const {encodeStrings, solveWithStrings, solveUnsafe} = solve
// (¬A ∨ B)∧(¬B ∨ C)∧(¬C ∨ A)
const formula1 = [['!A', 'B'], ['!B', 'C'], ['!C', 'A']]
const assumptions1 = []
const intFormula1 = [[-1, 2], [-2, 3], [-3, 1]]
const intAssumptions1 = []
const [encFormula1, encAssumptions1] = encodeStrings(formula1, assumptions1)
const formula2 = [
['!A', 'B', 'C'],
['!B', 'C'],
['!C', 'D'],
['!D', 'A', 'B', 'C']
]
const assumptions2 = ['A', '!C']
const intFormula2 = [
[-1, 2, 3],
[-2, 3],
[-3, 4],
[-4, 1, 2, 3]
]
const intAssumptions2 = [1, -3]
const [encFormula2, encAssumptions2] = encodeStrings(formula2, assumptions2)
new Suite()
.add('example 1 – solveWithStrings', function () {
solveWithStrings(formula1, assumptions1)
})
.add('example 1 – solve', function () {
solve(intFormula1, intAssumptions1)
})
.add('example 1 – solveUnsafe', function () {
solveUnsafe(encFormula1, encAssumptions1)
})
.add('example 2 – solveWithStrings', function () {
solveWithStrings(formula2, assumptions2)
})
.add('example 2 – solve', function () {
solve(intFormula2, intAssumptions2)
})
.add('example 2 – solveUnsafe', function () {
solveUnsafe(encFormula2, encAssumptions2)
})
.on('error', (err) => {
console.error(err)
process.exitCode = 1
})
.on('cycle', (e) => {
console.log(e.target.toString())
})
.run()