1
1
mirror of https://github.com/github/semantic.git synced 2024-11-29 02:44:36 +03:00

Convert ranges to JSON in less than 20s.

This is bad and I feel bad.
This commit is contained in:
Rob Rix 2015-10-20 16:27:07 -04:00
parent 0a11552638
commit 5e7f3af600

View File

@ -43,8 +43,16 @@ func diffAndSerialize(a aString: String, b bString: String) -> String? {
Interpreter<CofreeJSON>(equal: CofreeJSON.equals(annotation: const(true), leaf: ==), comparable: const(true), cost: Free.sum(Patch.difference)).run(a, b)
}
let range: Range<String.Index> -> Doubt.JSON = {
let start = Int(String($0.startIndex))!
let end = Int(String($0.endIndex))!
return [
.Number(Double(start)),
.Number(Double(end - start)),
]
}
let JSON = benchmark("converting diff to JSON") {
diff.JSON(ifPure: { $0.JSON(a: aString, b: bString) }, ifLeaf: { $0.JSON })
diff.JSON(ifPure: { $0.JSON { $0.JSON(annotation: range, leaf: { $0.JSON }) } }, ifLeaf: { $0.JSON })
}
let data = benchmark("serializing JSON to NSData") {