Created
July 18, 2011 07:09
-
-
Save josephg/1088748 to your computer and use it in GitHub Desktop.
OT Benchmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type = require './src/text' | |
fs = require 'fs' | |
assert = require 'assert' | |
check = (ops, check) -> | |
for {doc, op1, op2, result} in ops | |
op1_ = type.transform op1, op2, -1 | |
op2_ = type.transform op2, op1, 1 | |
op12 = type.compose op1, op2_ | |
op21 = type.compose op2, op1_ | |
doc12 = type.apply doc, op12 | |
doc21 = type.apply doc, op21 | |
if check | |
assert.deepEqual doc12, doc21 | |
assert.deepEqual doc12, result | |
return | |
ops = for line in fs.readFileSync('ops.json', 'utf8').split('\n') when line != '' | |
JSON.parse line | |
console.log "Read #{ops.length} ops" | |
console.time 'check' | |
check ops, false for [1..100] | |
console.timeEnd 'check' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type = require './src/text' | |
# Add the random generation functions | |
require './test/text' | |
fs = require 'fs' | |
file = fs.createWriteStream 'ops.json', {flags:'w'} | |
write = (data) -> file.write JSON.stringify(data) + '\n' | |
for [1..10000] | |
doc = type.generateRandomDoc() | |
[op1] = type.generateRandomOp doc | |
[op2] = type.generateRandomOp doc | |
op2_ = type.transform op2, op1, 1 | |
result = [op1, op2_].reduce type.apply, doc | |
write {doc, op1, op2, result} | |
file.end() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Read 10000 ops | |
check: 54028ms |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment