Skip to content

Instantly share code, notes, and snippets.

@briancavalier
Last active May 5, 2016 02:50
Show Gist options
  • Select an option

  • Save briancavalier/a5119fc58c8ccdfa3329b9c6d55306c4 to your computer and use it in GitHub Desktop.

Select an option

Save briancavalier/a5119fc58c8ccdfa3329b9c6d55306c4 to your computer and use it in GitHub Desktop.
esnextbin sketch
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Sliders</title>
</head>
<body>
<div id="app">
</body>
</html>
import { periodic } from 'most'
import { Observable } from '@reactivex/rxjs'
// period
const p = 1
// number of events
const n = 1000
const elapsed = (name, start) => document.write(`${name} ${Date.now() - start}<br/>`)
const runRx = () => {
const start = Date.now()
Observable.interval(p).take(n).subscribe({
next() {},
error() {},
complete() {
elapsed('rxjs', start)
}
})
}
const runMost = () => {
const start = Date.now()
// most periodic first event is at time zero, whereas
// rxjs interval first event is at time p, so use
// delay(p) here to normalize to rxjs semantics
return periodic(p).delay(p).take(n).drain()
.then(() => elapsed('most', start))
}
runMost().then(runRx)
{
"name": "esnextbin-sketch",
"version": "0.0.0",
"dependencies": {
"most": "0.19.2",
"@reactivex/rxjs": "5.0.0-beta.7"
}
}
'use strict';
var _most = require('most');
var _rxjs = require('@reactivex/rxjs');
// period
var p = 1;
// number of events
var n = 1000;
var elapsed = function elapsed(name, start) {
return document.write(name + ' ' + (Date.now() - start) + '<br/>');
};
var runRx = function runRx() {
var start = Date.now();
_rxjs.Observable.interval(p).take(n).subscribe({
next: function next() {},
error: function error() {},
complete: function complete() {
elapsed('rxjs', start);
}
});
};
var runMost = function runMost() {
var start = Date.now();
// most periodic first event is at time zero, whereas
// rxjs interval first event is at time p, so use
// delay(p) here to normalize to rxjs semantics
return (0, _most.periodic)(p).delay(p).take(n).drain().then(function () {
return elapsed('most', start);
});
};
runMost().then(runRx);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment