Skip to content

Commit

Permalink
CPS and yield: end of life
Browse files Browse the repository at this point in the history
  • Loading branch information
arjunguha committed Nov 3, 2017
1 parent fb6b95c commit f593dfe
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
Stopify: CPS and Yield End-of-Life
==================================

This repository has Stopify's CPS and generator based implementations of
continuations. We find that they are significantly slower than the approach
that Stopify now uses. To observe this, run the following script to time CPS
and generator based continuations:

yarn install
yarn run build
./compare.sh

The script builds and runs `./triangle.js` without ever yielding. You'll find
that it is 3x (CPS) or 2x (generator) slower than compiling with Stopify
"jumper"-based strategies.

## Stopify [![Build Status](http://23.20.114.147:5000/buildStatus/icon?job=stopify-build/master)](http://23.20.114.147:5000/job/stopify-build/job/master/)

Web-based programming environments lack many basic features that programmers
Expand Down
9 changes: 9 additions & 0 deletions compare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

echo "**** CPS ****"
./bin/stopify --optimize -t cps -i triangle.js > triangle.cps.js
node --harmony_tailcalls triangle.cps.js

echo "**** Generators ****"
./bin/stopify --optimize -t yield -i triangle.js > triangle.yield.js
node --harmony_tailcalls triangle.yield.js
15 changes: 15 additions & 0 deletions triangle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';

function triangle(n) {
if (n === 0) {
return 1;
}
else {
return n + triangle(n - 1);
}
}

var r = 0;
for (var i = 0; i < 150000; i++) {
r = (i % 2) + triangle(1000);
}
8 changes: 1 addition & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2719,7 +2719,7 @@ ms@2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"

nan@>=2.0.0, nan@^2.3.0:
nan@^2.3.0:
version "2.6.2"
resolved "https://registry.yarnpkg.com/nan/-/nan-2.6.2.tgz#e4ff34e6c95fdfb5aecc08de6596f43605a7db45"

Expand Down Expand Up @@ -3508,12 +3508,6 @@ slash@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/slash/-/slash-1.0.0.tgz#c41f2f6c39fc16d1cd17ad4b5d896114ae470d55"

sleep@3.0.x:
version "3.0.1"
resolved "https://registry.yarnpkg.com/sleep/-/sleep-3.0.1.tgz#be4d17c579360e07e04ed8172ba2b10a69054df3"
dependencies:
nan ">=2.0.0"

sntp@1.x.x:
version "1.0.9"
resolved "https://registry.yarnpkg.com/sntp/-/sntp-1.0.9.tgz#6541184cc90aeea6c6e7b35e2659082443c66198"
Expand Down

0 comments on commit f593dfe

Please sign in to comment.