-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Decreased the running time of benchmark/benchmark.js from: $ node --prof benchmark/benchmark.js number of operations: 100000 cons: 384ms tail: 544ms push: 338ms split: 7090ms init: 493ms to: $ node benchmark/benchmark.js number of operations: 100000 cons: 96ms tail: 218ms push: 75ms split: 1298ms init: 178ms
- Loading branch information
1 parent
1eeb30f
commit 295011e
Showing
20 changed files
with
1,305 additions
and
1,629 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
function CachedMeasure ( M ) { | ||
this.M = M ; | ||
} | ||
|
||
CachedMeasure.prototype.zero = function ( ) { | ||
return this.M.zero( ) ; | ||
} ; | ||
|
||
CachedMeasure.prototype.plus = function ( a , b ) { | ||
return this.M.plus( a , b ) ; | ||
} ; | ||
|
||
CachedMeasure.prototype.measure = function ( measured ) { | ||
return measured.measure( ) ; | ||
} ; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,3 @@ | ||
|
||
class CachedMeasure { | ||
|
||
constructor ( M ) { | ||
this.M = M ; | ||
} | ||
|
||
zero ( ) { | ||
return this.M.zero( ) ; | ||
} | ||
|
||
plus ( a , b ) { | ||
return this.M.plus( a , b ) ; | ||
} | ||
|
||
measure ( measured ) { | ||
return measured.measure( ) ; | ||
} | ||
|
||
} | ||
|
||
function cache ( M ) { | ||
|
||
return M instanceof CachedMeasure ? M : new CachedMeasure( M ) ; | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,3 @@ | ||
class _EmptyGenerator { | ||
function _EmptyGenerator ( ) { } | ||
|
||
next ( ) { | ||
|
||
return { done : true } ; | ||
|
||
} | ||
|
||
} | ||
_EmptyGenerator.prototype.next = function ( ) { return { done : true } ; } ; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,5 @@ | ||
|
||
class Split { | ||
|
||
constructor ( left , middle , right ) { | ||
this.left = left ; | ||
this.middle = middle ; | ||
this.right = right ; | ||
} | ||
|
||
function Split ( left , middle , right ) { | ||
this.left = left ; | ||
this.middle = middle ; | ||
this.right = right ; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,46 @@ | ||
class One { | ||
|
||
constructor ( a ) { | ||
this.a = a ; | ||
} | ||
|
||
*[Symbol.iterator] ( ) { | ||
yield this.a ; | ||
} | ||
function One ( a ) { | ||
this.a = a ; | ||
} | ||
|
||
measure ( M ) { | ||
return M.measure( this.a ) ; | ||
} | ||
One.prototype[Symbol.iterator] = function* ( ) { | ||
yield this.a ; | ||
} ; | ||
|
||
head ( ) { | ||
return this.a ; | ||
} | ||
One.prototype.measure = function ( M ) { | ||
return M.measure( this.a ) ; | ||
} ; | ||
|
||
last ( ) { | ||
return this.a ; | ||
} | ||
One.prototype.head = function ( ) { | ||
return this.a ; | ||
} ; | ||
|
||
init ( ) { | ||
throw new Error( "cannot call init on digit One" ) ; | ||
} | ||
One.prototype.last = function ( ) { | ||
return this.a ; | ||
} ; | ||
|
||
tail ( ) { | ||
throw new Error( "cannot call tail on digit One" ) ; | ||
} | ||
One.prototype.init = function ( ) { | ||
throw new Error( "cannot call init on digit One" ) ; | ||
} ; | ||
|
||
push ( value ) { | ||
return new Two( this.a , value ) ; | ||
} | ||
One.prototype.tail = function ( ) { | ||
throw new Error( "cannot call tail on digit One" ) ; | ||
} ; | ||
|
||
cons ( value ) { | ||
return new Two( value , this.a ) ; | ||
} | ||
One.prototype.push = function ( value ) { | ||
return new Two( this.a , value ) ; | ||
} ; | ||
|
||
node ( M ) { | ||
throw new Error( "cannot convert One to node" ) ; | ||
} | ||
One.prototype.cons = function ( value ) { | ||
return new Two( value , this.a ) ; | ||
} ; | ||
|
||
/** | ||
* It is assumed that p(|this|) is true. | ||
*/ | ||
splitDigit ( p , i , M ) { | ||
return new Split( [ ] , this.a , [ ] ) ; | ||
} | ||
One.prototype.node = function ( M ) { | ||
throw new Error( "cannot convert One to node" ) ; | ||
} ; | ||
|
||
} | ||
/** | ||
* It is assumed that p(|this|) is true. | ||
*/ | ||
One.prototype.splitDigit = function ( p , i , M ) { | ||
return new Split( [ ] , this.a , [ ] ) ; | ||
} ; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,50 @@ | ||
class Two { | ||
|
||
constructor ( a , b ) { | ||
this.a = a ; | ||
this.b = b ; | ||
} | ||
|
||
*[Symbol.iterator] ( ) { | ||
yield this.a ; | ||
yield this.b ; | ||
} | ||
|
||
measure ( M ) { | ||
return M.plus( M.measure( this.a ) , M.measure( this.b ) ) ; | ||
} | ||
|
||
head ( ) { | ||
return this.a ; | ||
} | ||
|
||
last ( ) { | ||
return this.b ; | ||
} | ||
|
||
init ( ) { | ||
return new One( this.a ) ; | ||
} | ||
|
||
tail ( ) { | ||
return new One( this.b ) ; | ||
} | ||
|
||
push ( value ) { | ||
return new Three( this.a , this.b , value ) ; | ||
} | ||
|
||
cons ( value ) { | ||
return new Three( value , this.a , this.b ) ; | ||
} | ||
|
||
node ( M ) { | ||
throw new Error( "Two should never be converted to Node2 with current implementation" ) ; | ||
} | ||
|
||
/** | ||
* It is assumed that p(|this|) is true. | ||
*/ | ||
splitDigit ( p , i , M ) { | ||
i = M.plus( i , M.measure( this.a ) ) ; | ||
if ( p( i ) ) return new Split( [ ] , this.a , [ this.b ] ) ; | ||
return new Split( [ this.a ] , this.b , [ ] ) ; | ||
} | ||
|
||
function Two ( a , b ) { | ||
this.a = a ; | ||
this.b = b ; | ||
} | ||
|
||
Two.prototype[Symbol.iterator] = function* ( ) { | ||
yield this.a ; | ||
yield this.b ; | ||
} ; | ||
|
||
Two.prototype.measure = function ( M ) { | ||
return M.plus( M.measure( this.a ) , M.measure( this.b ) ) ; | ||
} ; | ||
|
||
Two.prototype.head = function ( ) { | ||
return this.a ; | ||
} ; | ||
|
||
Two.prototype.last = function ( ) { | ||
return this.b ; | ||
} ; | ||
|
||
Two.prototype.init = function ( ) { | ||
return new One( this.a ) ; | ||
} ; | ||
|
||
Two.prototype.tail = function ( ) { | ||
return new One( this.b ) ; | ||
} ; | ||
|
||
Two.prototype.push = function ( value ) { | ||
return new Three( this.a , this.b , value ) ; | ||
} ; | ||
|
||
Two.prototype.cons = function ( value ) { | ||
return new Three( value , this.a , this.b ) ; | ||
} ; | ||
|
||
Two.prototype.node = function ( M ) { | ||
throw new Error( "Two should never be converted to Node2 with current implementation" ) ; | ||
} ; | ||
|
||
/** | ||
* It is assumed that p(|this|) is true. | ||
*/ | ||
Two.prototype.splitDigit = function ( p , i , M ) { | ||
i = M.plus( i , M.measure( this.a ) ) ; | ||
if ( p( i ) ) return new Split( [ ] , this.a , [ this.b ] ) ; | ||
return new Split( [ this.a ] , this.b , [ ] ) ; | ||
} ; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,60 @@ | ||
class Three { | ||
|
||
constructor ( a , b , c ) { | ||
this.a = a ; | ||
this.b = b ; | ||
this.c = c ; | ||
} | ||
|
||
*[Symbol.iterator] ( ) { | ||
yield this.a ; | ||
yield this.b ; | ||
yield this.c ; | ||
} | ||
|
||
measure ( M ) { | ||
return M.plus( | ||
M.measure( this.a ) , | ||
M.plus( | ||
M.measure( this.b ) , | ||
M.measure( this.c ) | ||
) | ||
) ; | ||
} | ||
|
||
head ( ) { | ||
return this.a ; | ||
} | ||
|
||
last ( ) { | ||
return this.c ; | ||
} | ||
|
||
init ( ) { | ||
return new Two( this.a , this.b ) ; | ||
} | ||
|
||
tail ( ) { | ||
return new Two( this.b , this.c ) ; | ||
} | ||
|
||
push ( value ) { | ||
return new Four( this.a , this.b , this.c , value ) ; | ||
} | ||
|
||
cons ( value ) { | ||
return new Four( value , this.a , this.b , this.c ) ; | ||
} | ||
|
||
node ( M ) { | ||
return node3( M , this.a , this.b , this.c ) ; | ||
} | ||
|
||
/** | ||
* It is assumed that p(|this|) is true. | ||
*/ | ||
splitDigit ( p , i , M ) { | ||
i = M.plus( i , M.measure( this.a ) ) ; | ||
if ( p( i ) ) return new Split( [ ] , this.a , [ this.b , this.c ] ) ; | ||
i = M.plus( i , M.measure( this.b ) ) ; | ||
if ( p( i ) ) return new Split( [ this.a ] , this.b , [ this.c ] ) ; | ||
return new Split( [ this.a , this.b ] , this.c , [ ] ) ; | ||
} | ||
|
||
function Three ( a , b , c ) { | ||
this.a = a ; | ||
this.b = b ; | ||
this.c = c ; | ||
} | ||
|
||
Three.prototype[Symbol.iterator] = function* ( ) { | ||
yield this.a ; | ||
yield this.b ; | ||
yield this.c ; | ||
} ; | ||
|
||
Three.prototype.measure = function ( M ) { | ||
return M.plus( | ||
M.measure( this.a ) , | ||
M.plus( | ||
M.measure( this.b ) , | ||
M.measure( this.c ) | ||
) | ||
) ; | ||
} ; | ||
|
||
Three.prototype.head = function ( ) { | ||
return this.a ; | ||
} ; | ||
|
||
Three.prototype.last = function ( ) { | ||
return this.c ; | ||
} ; | ||
|
||
Three.prototype.init = function ( ) { | ||
return new Two( this.a , this.b ) ; | ||
} ; | ||
|
||
Three.prototype.tail = function ( ) { | ||
return new Two( this.b , this.c ) ; | ||
} ; | ||
|
||
Three.prototype.push = function ( value ) { | ||
return new Four( this.a , this.b , this.c , value ) ; | ||
} ; | ||
|
||
Three.prototype.cons = function ( value ) { | ||
return new Four( value , this.a , this.b , this.c ) ; | ||
} ; | ||
|
||
Three.prototype.node = function ( M ) { | ||
return node3( M , this.a , this.b , this.c ) ; | ||
} ; | ||
|
||
/** | ||
* It is assumed that p(|this|) is true. | ||
*/ | ||
Three.prototype.splitDigit = function ( p , i , M ) { | ||
i = M.plus( i , M.measure( this.a ) ) ; | ||
if ( p( i ) ) return new Split( [ ] , this.a , [ this.b , this.c ] ) ; | ||
i = M.plus( i , M.measure( this.b ) ) ; | ||
if ( p( i ) ) return new Split( [ this.a ] , this.b , [ this.c ] ) ; | ||
return new Split( [ this.a , this.b ] , this.c , [ ] ) ; | ||
} ; |
Oops, something went wrong.