Last active
September 30, 2017 23:44
-
-
Save natefaubion/7fe08a9602468a69946e6c69362e0345 to your computer and use it in GitHub Desktop.
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
"use strict"; | |
var $foreign = require("./foreign"); | |
var Control_Applicative = require("../Control.Applicative"); | |
var Control_Bind = require("../Control.Bind"); | |
var Control_Monad_Eff = require("../Control.Monad.Eff"); | |
var Control_Monad_Eff_Console = require("../Control.Monad.Eff.Console"); | |
var Control_Monad_Error_Class = require("../Control.Monad.Error.Class"); | |
var Control_Monad_Except = require("../Control.Monad.Except"); | |
var Control_Monad_Except_Trans = require("../Control.Monad.Except.Trans"); | |
var Control_Monad_Free = require("../Control.Monad.Free"); | |
var Control_Monad_State = require("../Control.Monad.State"); | |
var Control_Monad_State_Class = require("../Control.Monad.State.Class"); | |
var Control_Monad_State_Trans = require("../Control.Monad.State.Trans"); | |
var Control_Monad_Trampoline = require("../Control.Monad.Trampoline"); | |
var Control_Monad_Writer = require("../Control.Monad.Writer"); | |
var Control_Monad_Writer_Class = require("../Control.Monad.Writer.Class"); | |
var Control_Monad_Writer_Trans = require("../Control.Monad.Writer.Trans"); | |
var Data_Function = require("../Data.Function"); | |
var Data_Identity = require("../Data.Identity"); | |
var Data_Monoid = require("../Data.Monoid"); | |
var Data_Newtype = require("../Data.Newtype"); | |
var Data_Ord = require("../Data.Ord"); | |
var Data_Ring = require("../Data.Ring"); | |
var Data_Semiring = require("../Data.Semiring"); | |
var Data_Show = require("../Data.Show"); | |
var Performance_Minibench = require("../Performance.Minibench"); | |
var Prelude = require("../Prelude"); | |
var Run = require("../Run"); | |
var Run_Except = require("../Run.Except"); | |
var Run_State = require("../Run.State"); | |
var Run_Writer = require("../Run.Writer"); | |
var test_run = (function () { | |
var test_error = Control_Bind.discard(Control_Bind.discardUnit)(Run.bindRun)(Run_State.modify(function (v) { | |
return v + 1 | 0; | |
}))(function () { | |
return Control_Bind.bind(Run.bindRun)(Run_State.get)(function (v) { | |
return Run_Except["throw"](Data_Show.show(Data_Show.showInt)(v)); | |
}); | |
}); | |
var test_inner = Control_Bind.discard(Control_Bind.discardUnit)(Run.bindRun)(Run_State.modify(function (v) { | |
return v - 2 | 0; | |
}))(function () { | |
return Control_Bind.discard(Control_Bind.discardUnit)(Run.bindRun)(Run_Except["catch"](Run_Writer.tell)(test_error))(function () { | |
return test_run; | |
}); | |
}); | |
return Control_Bind.bind(Run.bindRun)(Run_State.get)(function (v) { | |
var $26 = v <= 0; | |
if ($26) { | |
return Control_Applicative.pure(Run.applicativeRun)(0); | |
}; | |
return test_inner; | |
}); | |
})(); | |
var test_mtl = function (dictMonadState) { | |
return function (dictMonadWriter) { | |
return function (dictMonadError) { | |
var test_error = Control_Bind.discard(Control_Bind.discardUnit)((dictMonadState.Monad0()).Bind1())(Control_Monad_State_Class.modify(dictMonadState)(function (v) { | |
return v + 1 | 0; | |
}))(function () { | |
return Control_Bind.bind((dictMonadState.Monad0()).Bind1())(Control_Monad_State_Class.get(dictMonadState))(function (v) { | |
return Control_Monad_Error_Class.throwError(dictMonadError.MonadThrow0())(Data_Show.show(Data_Show.showInt)(v)); | |
}); | |
}); | |
var test_inner = Control_Bind.discard(Control_Bind.discardUnit)((dictMonadState.Monad0()).Bind1())(Control_Monad_State_Class.modify(dictMonadState)(function (v) { | |
return v - 2 | 0; | |
}))(function () { | |
return Control_Bind.discard(Control_Bind.discardUnit)((dictMonadState.Monad0()).Bind1())(Control_Monad_Error_Class.catchError(dictMonadError)(test_error)(Control_Monad_Writer_Class.tell(dictMonadWriter.MonadTell0())))(function () { | |
return test_mtl(dictMonadState)(dictMonadWriter)(dictMonadError); | |
}); | |
}); | |
return Control_Bind.bind((dictMonadState.Monad0()).Bind1())(Control_Monad_State_Class.get(dictMonadState))(function (v) { | |
var $29 = v <= 0; | |
if ($29) { | |
return Control_Applicative.pure((dictMonadState.Monad0()).Applicative0())(0); | |
}; | |
return test_inner; | |
}); | |
}; | |
}; | |
}; | |
var test_mono$prime = (function () { | |
var test_error = Control_Bind.discard(Control_Bind.discardUnit)(Control_Monad_Except_Trans.bindExceptT(Control_Monad_Writer_Trans.monadWriterT(Data_Monoid.monoidString)(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity))))(Control_Monad_State_Class.modify(Control_Monad_Except_Trans.monadStateExceptT(Control_Monad_Writer_Trans.monadStateWriterT(Data_Monoid.monoidString)(Control_Monad_State_Trans.monadStateStateT(Data_Identity.monadIdentity))))(function (v) { | |
return v + 1 | 0; | |
}))(function () { | |
return Control_Bind.bind(Control_Monad_Except_Trans.bindExceptT(Control_Monad_Writer_Trans.monadWriterT(Data_Monoid.monoidString)(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity))))(Control_Monad_State_Class.get(Control_Monad_Except_Trans.monadStateExceptT(Control_Monad_Writer_Trans.monadStateWriterT(Data_Monoid.monoidString)(Control_Monad_State_Trans.monadStateStateT(Data_Identity.monadIdentity)))))(function (v) { | |
return Control_Monad_Error_Class.throwError(Control_Monad_Except_Trans.monadThrowExceptT(Control_Monad_Writer_Trans.monadWriterT(Data_Monoid.monoidString)(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity))))(Data_Show.show(Data_Show.showInt)(v)); | |
}); | |
}); | |
var test_inner = Control_Bind.discard(Control_Bind.discardUnit)(Control_Monad_Except_Trans.bindExceptT(Control_Monad_Writer_Trans.monadWriterT(Data_Monoid.monoidString)(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity))))(Control_Monad_State_Class.modify(Control_Monad_Except_Trans.monadStateExceptT(Control_Monad_Writer_Trans.monadStateWriterT(Data_Monoid.monoidString)(Control_Monad_State_Trans.monadStateStateT(Data_Identity.monadIdentity))))(function (v) { | |
return v - 2 | 0; | |
}))(function () { | |
return Control_Bind.discard(Control_Bind.discardUnit)(Control_Monad_Except_Trans.bindExceptT(Control_Monad_Writer_Trans.monadWriterT(Data_Monoid.monoidString)(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity))))(Control_Monad_Error_Class.catchError(Control_Monad_Except_Trans.monadErrorExceptT(Control_Monad_Writer_Trans.monadWriterT(Data_Monoid.monoidString)(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity))))(test_error)(Control_Monad_Writer_Class.tell(Control_Monad_Except_Trans.monadTellExceptT(Control_Monad_Writer_Trans.monadTellWriterT(Data_Monoid.monoidString)(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity))))))(function () { | |
return test_mono$prime; | |
}); | |
}); | |
return Control_Bind.bind(Control_Monad_Except_Trans.bindExceptT(Control_Monad_Writer_Trans.monadWriterT(Data_Monoid.monoidString)(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity))))(Control_Monad_State_Class.get(Control_Monad_Except_Trans.monadStateExceptT(Control_Monad_Writer_Trans.monadStateWriterT(Data_Monoid.monoidString)(Control_Monad_State_Trans.monadStateStateT(Data_Identity.monadIdentity)))))(function (v) { | |
var $32 = v <= 0; | |
if ($32) { | |
return Control_Applicative.pure(Control_Monad_Except_Trans.applicativeExceptT(Control_Monad_Writer_Trans.monadWriterT(Data_Monoid.monoidString)(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity))))(0); | |
}; | |
return test_inner; | |
}); | |
})(); | |
var test_mono = (function () { | |
var test_error = Control_Bind.discard(Control_Bind.discardUnit)(Control_Monad_Except_Trans.bindExceptT(Control_Monad_Writer_Trans.monadWriterT(Data_Monoid.monoidString)(Control_Monad_State_Trans.monadStateT(Control_Monad_Free.freeMonad))))(Control_Monad_State_Class.modify(Control_Monad_Except_Trans.monadStateExceptT(Control_Monad_Writer_Trans.monadStateWriterT(Data_Monoid.monoidString)(Control_Monad_State_Trans.monadStateStateT(Control_Monad_Free.freeMonad))))(function (v) { | |
return v + 1 | 0; | |
}))(function () { | |
return Control_Bind.bind(Control_Monad_Except_Trans.bindExceptT(Control_Monad_Writer_Trans.monadWriterT(Data_Monoid.monoidString)(Control_Monad_State_Trans.monadStateT(Control_Monad_Free.freeMonad))))(Control_Monad_State_Class.get(Control_Monad_Except_Trans.monadStateExceptT(Control_Monad_Writer_Trans.monadStateWriterT(Data_Monoid.monoidString)(Control_Monad_State_Trans.monadStateStateT(Control_Monad_Free.freeMonad)))))(function (v) { | |
return Control_Monad_Error_Class.throwError(Control_Monad_Except_Trans.monadThrowExceptT(Control_Monad_Writer_Trans.monadWriterT(Data_Monoid.monoidString)(Control_Monad_State_Trans.monadStateT(Control_Monad_Free.freeMonad))))(Data_Show.show(Data_Show.showInt)(v)); | |
}); | |
}); | |
var test_inner = Control_Bind.discard(Control_Bind.discardUnit)(Control_Monad_Except_Trans.bindExceptT(Control_Monad_Writer_Trans.monadWriterT(Data_Monoid.monoidString)(Control_Monad_State_Trans.monadStateT(Control_Monad_Free.freeMonad))))(Control_Monad_State_Class.modify(Control_Monad_Except_Trans.monadStateExceptT(Control_Monad_Writer_Trans.monadStateWriterT(Data_Monoid.monoidString)(Control_Monad_State_Trans.monadStateStateT(Control_Monad_Free.freeMonad))))(function (v) { | |
return v - 2 | 0; | |
}))(function () { | |
return Control_Bind.discard(Control_Bind.discardUnit)(Control_Monad_Except_Trans.bindExceptT(Control_Monad_Writer_Trans.monadWriterT(Data_Monoid.monoidString)(Control_Monad_State_Trans.monadStateT(Control_Monad_Free.freeMonad))))(Control_Monad_Error_Class.catchError(Control_Monad_Except_Trans.monadErrorExceptT(Control_Monad_Writer_Trans.monadWriterT(Data_Monoid.monoidString)(Control_Monad_State_Trans.monadStateT(Control_Monad_Free.freeMonad))))(test_error)(Control_Monad_Writer_Class.tell(Control_Monad_Except_Trans.monadTellExceptT(Control_Monad_Writer_Trans.monadTellWriterT(Data_Monoid.monoidString)(Control_Monad_State_Trans.monadStateT(Control_Monad_Free.freeMonad))))))(function () { | |
return test_mono; | |
}); | |
}); | |
return Control_Bind.bind(Control_Monad_Except_Trans.bindExceptT(Control_Monad_Writer_Trans.monadWriterT(Data_Monoid.monoidString)(Control_Monad_State_Trans.monadStateT(Control_Monad_Free.freeMonad))))(Control_Monad_State_Class.get(Control_Monad_Except_Trans.monadStateExceptT(Control_Monad_Writer_Trans.monadStateWriterT(Data_Monoid.monoidString)(Control_Monad_State_Trans.monadStateStateT(Control_Monad_Free.freeMonad)))))(function (v) { | |
var $35 = v <= 0; | |
if ($35) { | |
return Control_Applicative.pure(Control_Monad_Except_Trans.applicativeExceptT(Control_Monad_Writer_Trans.monadWriterT(Data_Monoid.monoidString)(Control_Monad_State_Trans.monadStateT(Control_Monad_Free.freeMonad))))(0); | |
}; | |
return test_inner; | |
}); | |
})(); | |
var main = function __do() { | |
Control_Monad_Eff_Console.log("Transformers (monomorphic/trampoline)")(); | |
Performance_Minibench.benchWith(100)(function (v) { | |
return Control_Monad_Trampoline.runTrampoline(Data_Function.flip(Control_Monad_State_Trans.runStateT)(1000)(Control_Monad_Writer_Trans.runWriterT(Control_Monad_Except_Trans.runExceptT(test_mono)))); | |
})(); | |
$foreign.gc(); | |
Control_Monad_Eff_Console.log("Transformers (monomorphic/identity)")(); | |
Performance_Minibench.benchWith(100)(function (v) { | |
return Data_Newtype.un(Data_Identity.newtypeIdentity)(Data_Identity.Identity)(Data_Function.flip(Control_Monad_State_Trans.runStateT)(1000)(Control_Monad_Writer_Trans.runWriterT(Control_Monad_Except_Trans.runExceptT(test_mono$prime)))); | |
})(); | |
$foreign.gc(); | |
Control_Monad_Eff_Console.log("Transformers (mtl/trampoline)")(); | |
Performance_Minibench.benchWith(100)(function (v) { | |
return Control_Monad_Trampoline.runTrampoline(Data_Function.flip(Control_Monad_State_Trans.runStateT)(1000)(Control_Monad_Writer_Trans.runWriterT(Control_Monad_Except_Trans.runExceptT(test_mtl(Control_Monad_Except_Trans.monadStateExceptT(Control_Monad_Writer_Trans.monadStateWriterT(Data_Monoid.monoidString)(Control_Monad_State_Trans.monadStateStateT(Control_Monad_Free.freeMonad))))(Control_Monad_Except_Trans.monadWriterExceptT(Control_Monad_Writer_Trans.monadWriterWriterT(Data_Monoid.monoidString)(Control_Monad_State_Trans.monadStateT(Control_Monad_Free.freeMonad))))(Control_Monad_Except_Trans.monadErrorExceptT(Control_Monad_Writer_Trans.monadWriterT(Data_Monoid.monoidString)(Control_Monad_State_Trans.monadStateT(Control_Monad_Free.freeMonad)))))))); | |
})(); | |
$foreign.gc(); | |
Control_Monad_Eff_Console.log("Transformers (mtl/identity)")(); | |
Performance_Minibench.benchWith(100)(function (v) { | |
return Data_Newtype.un(Data_Identity.newtypeIdentity)(Data_Identity.Identity)(Data_Function.flip(Control_Monad_State_Trans.runStateT)(1000)(Control_Monad_Writer_Trans.runWriterT(Control_Monad_Except_Trans.runExceptT(test_mtl(Control_Monad_Except_Trans.monadStateExceptT(Control_Monad_Writer_Trans.monadStateWriterT(Data_Monoid.monoidString)(Control_Monad_State_Trans.monadStateStateT(Data_Identity.monadIdentity))))(Control_Monad_Except_Trans.monadWriterExceptT(Control_Monad_Writer_Trans.monadWriterWriterT(Data_Monoid.monoidString)(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity))))(Control_Monad_Except_Trans.monadErrorExceptT(Control_Monad_Writer_Trans.monadWriterT(Data_Monoid.monoidString)(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))))))); | |
})(); | |
$foreign.gc(); | |
Control_Monad_Eff_Console.log("Run (free)")(); | |
return Performance_Minibench.benchWith(100)(function (v) { | |
return Run.run(Run_State.runState(1000)(Run_Writer.runWriter(Data_Monoid.monoidString)(Run_Except.runExcept(test_run)))); | |
})(); | |
}; | |
module.exports = { | |
main: main, | |
test_mono: test_mono, | |
"test_mono'": test_mono$prime, | |
test_mtl: test_mtl, | |
test_run: test_run, | |
gc: $foreign.gc | |
}; |
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
module Test.Bench where | |
import Prelude | |
import Control.Monad.Eff (Eff) | |
import Control.Monad.Eff.Console (log) | |
import Control.Monad.Error.Class as EC | |
import Control.Monad.Except (ExceptT, runExceptT) | |
import Control.Monad.State (StateT, runStateT) | |
import Control.Monad.State.Class as SC | |
import Control.Monad.Trampoline (Trampoline, runTrampoline) | |
import Control.Monad.Writer (WriterT, runWriterT) | |
import Control.Monad.Writer.Class as WC | |
import Data.Identity (Identity(..)) | |
import Data.Newtype (un) | |
import Performance.Minibench (benchWith) | |
import Run (Run, run) | |
import Run.Except (EXCEPT) | |
import Run.Except as RE | |
import Run.State (STATE) | |
import Run.State as RS | |
import Run.Writer (WRITER) | |
import Run.Writer as RW | |
type TestT = ExceptT String (WriterT String (StateT Int Trampoline)) | |
type TestT' = ExceptT String (WriterT String (StateT Int Identity)) | |
type TestR = Run (state ∷ STATE Int, writer :: WRITER String, except ∷ EXCEPT String) | |
test_mono ∷ TestT Int | |
test_mono = do | |
x ← SC.get | |
if x <= 0 | |
then pure 0 | |
else test_inner | |
where | |
test_inner = do | |
SC.modify (_ - 2) | |
EC.catchError test_error WC.tell | |
test_mono | |
test_error = do | |
SC.modify (_ + 1) | |
x ← SC.get | |
EC.throwError (show x) | |
test_mono' ∷ TestT' Int | |
test_mono' = do | |
x ← SC.get | |
if x <= 0 | |
then pure 0 | |
else test_inner | |
where | |
test_inner = do | |
SC.modify (_ - 2) | |
EC.catchError test_error WC.tell | |
test_mono' | |
test_error = do | |
SC.modify (_ + 1) | |
x ← SC.get | |
EC.throwError (show x) | |
test_mtl | |
∷ ∀ m | |
. SC.MonadState Int m | |
⇒ WC.MonadWriter String m | |
⇒ EC.MonadError String m | |
⇒ m Int | |
test_mtl = do | |
x ← SC.get | |
if x <= 0 | |
then pure 0 | |
else test_inner | |
where | |
test_inner = do | |
SC.modify (_ - 2) | |
EC.catchError test_error WC.tell | |
test_mtl | |
test_error = do | |
SC.modify (_ + 1) | |
x ← SC.get | |
EC.throwError (show x) | |
test_run ∷ TestR Int | |
test_run = do | |
x ← RS.get | |
if x <= 0 | |
then pure 0 | |
else test_inner | |
where | |
test_inner = do | |
RS.modify (_ - 2) | |
test_error # RE.catch RW.tell | |
test_run | |
test_error = do | |
RS.modify (_ + 1) | |
x ← RS.get | |
RE.throw (show x) | |
main ∷ Eff _ Unit | |
main = do | |
log "Transformers (monomorphic/trampoline)" | |
benchWith 100 \_ → | |
test_mono | |
# runExceptT | |
# runWriterT | |
# flip runStateT 1000 | |
# runTrampoline | |
gc | |
log "Transformers (monomorphic/identity)" | |
benchWith 100 \_ → | |
test_mono' | |
# runExceptT | |
# runWriterT | |
# flip runStateT 1000 | |
# un Identity | |
gc | |
log "Transformers (mtl/trampoline)" | |
benchWith 100 \_ → | |
test_mtl | |
# runExceptT | |
# runWriterT | |
# flip runStateT 1000 | |
# runTrampoline | |
gc | |
log "Transformers (mtl/identity)" | |
benchWith 100 \_ → | |
test_mtl | |
# runExceptT | |
# runWriterT | |
# flip runStateT 1000 | |
# un Identity | |
gc | |
log "Run (free)" | |
benchWith 100 \_ → | |
test_run | |
# RE.runExcept | |
# RW.runWriter | |
# RS.runState 1000 | |
# run | |
foreign import gc :: forall eff. Eff eff Unit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment