-
-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor to classes #34
Merged
Merged
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
5877bd3
WIP: Convert several methods from higher-order style to class-style
Avaq 6eb1fe5
Fix test-opt script
Avaq 5727d43
Refactor Future.cache
Avaq 36bd594
Remove Future#recur in favor of Future.chainRec
Avaq ea78cd8
Fix bench/curry
Avaq 56144ca
Refactor chainRej
Avaq 3e893c8
Correct a typo
Avaq 0a43aa3
Refactor mapRej
Avaq f144ccc
Refactor Future.bimap
Avaq 471ece7
Fix inspect methods
Avaq b7294fa
Refactor Future.swap
Avaq f4bfa3d
Add race benchmark
Avaq aa6a3a7
Refactor Future.race
Avaq e34f1a6
Add Future.or benchmark
Avaq 7041f53
Refactor Future.or
Avaq becca2d
Refactor Future.fold
Avaq 1e5482e
Use normal toString semantics for CachedFuture
Avaq 6815f14
Refactor Future.hook
Avaq f86f468
Refactor Future.finally
Avaq 05f54e1
Move stuff around
Avaq b17a52a
Refactor static utilities to introspective classes
Avaq 2cd49ef
Add Future.parallel benchmark
Avaq 14157c6
Performance optimize Future.parallel
Avaq 72bc0dc
Fix a bug in CachedFuture
Avaq b223ff8
Restore code coverage
Avaq 2ca9baf
Improve curry benchmark, check perf diff between 3 ifs and switch
Avaq 51f8930
Improve the Future#hook readme example
Avaq ee9e247
Remove excess brackets from encase unit tests
Avaq 904c1be
Remove excess brackets from isFuture check
Avaq 405bf3c
Improve code for Future.encaseN functions
Avaq 27afcc7
Use named states in ChainRec
Avaq a4edcbf
Use named states in CachedFuture
Avaq fabb2fc
Optimization: `ok += 1` -> `ok = ok + 1`
Avaq ebc46b0
Replace "if a then a else b" ternary operators with "a or b"
Avaq File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,31 +1,56 @@ | ||
const benchmark = require('benchmark'); | ||
const suite = new benchmark.Suite(); | ||
const curry = require('lodash.curry'); | ||
const {util} = require('..'); | ||
|
||
const lodash = curry(function(a, b){ | ||
return a + b; | ||
}); | ||
|
||
const manual = function(a, b){ | ||
if(arguments.length === 1) return b => manual(a, b); | ||
function manual(a, b){ | ||
if(arguments.length === 1) return util.unaryPartial(manual, a); | ||
return a + b; | ||
}; | ||
} | ||
|
||
function manual3if(a, b, c, d){ | ||
if(arguments.length === 1) return util.unaryPartial(manual3if, a); | ||
if(arguments.length === 2) return util.binaryPartial(manual3if, a, b); | ||
if(arguments.length === 3) return util.ternaryPartial(manual3if, a, b, c); | ||
return a + b + c + d; | ||
} | ||
|
||
function manual3switch(a, b, c, d){ | ||
switch(arguments.length){ | ||
case 1: return util.unaryPartial(manual3switch, a); | ||
case 2: return util.binaryPartial(manual3switch, a, b); | ||
case 3: return util.ternaryPartial(manual3switch, a, b, c); | ||
default: return a + b + c + d; | ||
} | ||
} | ||
|
||
suite.add('Lodash uncurried', () => { | ||
lodash(1, 2); | ||
}); | ||
|
||
suite.add('Manual uncurried', () => { | ||
manual(1, 2); | ||
}); | ||
|
||
suite.add('Lodash curried', () => { | ||
lodash(1)(2); | ||
}); | ||
|
||
suite.add('Manual uncurried', () => { | ||
manual(1, 2); | ||
}); | ||
|
||
suite.add('Manual curried', () => { | ||
manual(1)(2); | ||
}); | ||
|
||
suite.add('Manual 3 (if)', () => { | ||
manual3if(1)(2)(3)(4); | ||
}); | ||
|
||
suite.add('Manual 3 (switch)', () => { | ||
manual3switch(1)(2)(3)(4); | ||
}); | ||
|
||
suite.on('complete', require('./_print')) | ||
suite.run() |
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,28 @@ | ||
const benchmark = require('benchmark'); | ||
const suite = new benchmark.Suite(); | ||
const Future = require('..'); | ||
|
||
const noop = () => {}; | ||
const a = Future.of('a'); | ||
const b = Future.of('b'); | ||
const _a = Future.reject('!a'); | ||
const _b = Future.reject('!b'); | ||
|
||
suite.add('res res', () => { | ||
a.or(b).fork(noop, noop); | ||
}); | ||
|
||
suite.add('rej rej', () => { | ||
_a.or(_b).fork(noop, noop); | ||
}); | ||
|
||
suite.add('rej res', () => { | ||
_a.or(b).fork(noop, noop); | ||
}); | ||
|
||
suite.add('res rej', () => { | ||
a.or(_b).fork(noop, noop); | ||
}); | ||
|
||
suite.on('complete', require('./_print')) | ||
suite.run() |
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,32 @@ | ||
const benchmark = require('benchmark'); | ||
const suite = new benchmark.Suite(); | ||
const Future = require('..'); | ||
|
||
const noop = () => {}; | ||
const makeArr = length => Array.from({length}, (_, i) => Future.of(i)); | ||
const empty = makeArr(0); | ||
const small = makeArr(2); | ||
const big = makeArr(100); | ||
|
||
suite.add('Empty', () => { | ||
Future.parallel(1, empty).fork(noop, noop); | ||
}); | ||
|
||
suite.add('Small concurrent', () => { | ||
Future.parallel(2, small).fork(noop, noop); | ||
}); | ||
|
||
suite.add('Small sequential', () => { | ||
Future.parallel(1, small).fork(noop, noop); | ||
}); | ||
|
||
suite.add('Big concurrent', () => { | ||
Future.parallel(Infinity, big).fork(noop, noop); | ||
}); | ||
|
||
suite.add('Big sequential', () => { | ||
Future.parallel(5, big).fork(noop, noop); | ||
}); | ||
|
||
suite.on('complete', require('./_print')) | ||
suite.run() |
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,26 @@ | ||
const benchmark = require('benchmark'); | ||
const suite = new benchmark.Suite(); | ||
const Future = require('..'); | ||
|
||
const noop = () => {}; | ||
const a = Future.of('a'); | ||
const b = Future.after(5, 'b'); | ||
|
||
suite.add('Left winner', () => { | ||
a.race(b).fork(noop, noop); | ||
}); | ||
|
||
suite.add('Right winner', () => { | ||
b.race(a).fork(noop, noop); | ||
}); | ||
|
||
suite.add('Both fast', () => { | ||
a.race(a).fork(noop, noop); | ||
}); | ||
|
||
suite.add('Both slow', () => { | ||
b.race(b).fork(noop, noop); | ||
}); | ||
|
||
suite.on('complete', require('./_print')) | ||
suite.run() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This obviously can wait for another PR/commit, but make this switch just to be consistent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. The idea here is to test the performance of
if
vsswitch
. That's why the function is called manual3if ^^There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
haha. Yup that makes sense 😛