t = TrafficLight(); b = Button(); es = []; b.onclick(function () { t.red(); es.push(now()); if (es.length == 6) report(); else start(); }); start = function () {setTimeout(go, Math.random() * 3000)} go = function () {t.green(); es.push(-now())}; div = function (a, b) {return Math.floor(a/b)}; report = function () { var ts = es.filter(not(pos)).zip(es.filter(pos), plus); print("Avg: " + div(ts.reduce(plus,0),ts.length) + "ms"); print("Max: " + ts.reduce(max, 0) + "ms"); }; start(); "Ready...";
Output