Permalink
Browse files

Cleaning up

  • Loading branch information...
1 parent 8358fb3 commit 00ab9af1abb8c98e57e0903aa65b272ec19322f2 Paul Taysom committed Mar 10, 2012
Showing with 93 additions and 31 deletions.
  1. +8 −29 tau.pj/js.t/canvas.d/graph.js
  2. +83 −0 tau.pj/tests.t/play.m/hist.c
  3. +2 −2 tau.pj/tests.t/play.m/prefix.c
@@ -56,11 +56,6 @@ Point.prototype = {
function Graph(n) {
this.values = [];
-/*
- for (var i = 0; i < n; i++) {
- this.addRandomValue();
- }
-*/
return graph;
}
@@ -108,8 +103,6 @@ Graph.prototype = {
}
ctx.stroke();
ctx.restore();
- /*
- */
}
function drawLine(xstart, ystart, xend, yend, color, width) {
@@ -142,7 +135,8 @@ Graph.prototype = {
var dtick = (mx.y - mn.y) / numYTicks;
var tick = dtick + mn.y;
for (var i = 0; i < numYTicks; i++) {
- label(Math.round(tick), leftMargin, yScale(tick));
+ label(Math.round(tick), leftMargin,
+ yScale(tick));
drawLine(mn.x, tick, mx.x, tick,
'#0F0', gridWidth);
tick += dtick;
@@ -152,11 +146,13 @@ Graph.prototype = {
function yAxis() {
yLabel('y axis');
drawLine(mn.x, mn.y, mn.x, mx.y, axisColor, axisWidth);
- label(Math.round(tick), xScale(tick), canvas.height - bottomMargin + 10);
+ label(Math.round(tick), xScale(tick),
+ canvas.height - bottomMargin + 10);
var dtick = (mx.x - mn.x) / numXTicks;
var tick = mn.x + dtick;
for (var i = 0; i < numXTicks; i++) {
- label(Math.round(tick), xScale(tick), canvas.height - bottomMargin + 10);
+ label(Math.round(tick), xScale(tick),
+ canvas.height - bottomMargin + 10);
drawLine(tick, mn.y, tick, mx.y,
'#0F0', gridWidth);
tick += dtick;
@@ -167,7 +163,8 @@ Graph.prototype = {
ctx.save();
ctx.strokeStyle = '#0F0';
ctx.lineWidth = 1;
- ctx.strokeText(text, canvas.width / 2, canvas.height - bottomMargin / 2);
+ ctx.strokeText(text, canvas.width / 2,
+ canvas.height - bottomMargin / 2);
ctx.restore();
}
@@ -207,8 +204,6 @@ function pickAplot() {
}
function step() {
-// graph.addRandomValue();
-// graph.draw();
$.get(thePlot, handleResponse);
}
@@ -237,13 +232,6 @@ function run() {
pickAplot();
-/*
- $('body').click(function(e) {
- g.push(Math.random() * 1000); // g = genGraph(100);
- drawGraph(g);
- });
-*/
-
resume();
}
@@ -268,13 +256,4 @@ function handleResponse(response) {
}
}
-function plot() {
- canvas = $('#canvas').get(0);
- ctx = canvas.getContext('2d');
-
- $.get("data", handleResponse);
-}
-
-//$(plot);
-
})();
@@ -0,0 +1,83 @@
+/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <debug.h>
+#include <eprintf.h>
+#include <puny.h>
+#include <style.h>
+#include <timer.h>
+#include <twister.h>
+
+/* test pseudo-random number generators */
+
+typedef u64 (*rnd_f)(void);
+
+static void timer (char *name, rnd_f rnd)
+{
+ u64 start;
+ u64 finish;
+ u64 sum = 0;
+ unint i = Option.iterations;
+
+ start = nsecs();
+ while (i--) {
+ sum += rnd();
+ }
+ finish = nsecs();
+ printf("%-20s: %g nsecs/rnd sum=%lld\n",
+ name,
+ (double)(finish - start) / (double)Option.iterations,
+ sum);
+}
+
+#define TIMER(_rng) { \
+ u64 start; \
+ u64 finish; \
+ u64 sum = 0; \
+ unint i = Option.iterations; \
+ \
+ start = nsecs(); \
+ while (i--) { \
+ sum += _rng; \
+ } \
+ finish = nsecs(); \
+ printf("%-20s: %g nsecs/rnd sum=%lld\n", \
+ # _rng, \
+ (double)(finish - start) / (double)Option.iterations, \
+ sum); \
+}
+
+
+int main (int argc, char *argv[])
+{
+#if 0
+ unsigned long long init[4]={0x12345ULL, 0x23456ULL,
+ 0x34567ULL, 0x45678ULL}, length=4;
+ init_by_array64(init, length);
+#endif
+ Twister_s twister;
+ int i;
+
+ punyopt(argc, argv, NULL, NULL);
+ TIMER(rand());
+ TIMER(random());
+ TIMER(twister_random());
+ TIMER(twister_random());
+ timer("rand", (rnd_f)rand);
+ timer("random", (rnd_f)random);
+ timer("twister_random", (rnd_f)twister_random);
+ TIMER(rand());
+ TIMER(random());
+ TIMER(twister_random());
+ for (i = 0; i < Option.numthreads; i++) {
+ init_twister_r(17, &twister);
+ TIMER(twister_random_r(&twister));
+ }
+ init_twister_r(17, &twister);
+ TIMER(twister_random_r(&twister));
+ return 0;
+}
@@ -57,7 +57,7 @@ Lump_s prefix(Lump_s a, Lump_s b) {
size = a.size;
}
for (i = 0; i < size; i++) {
- if (a.d[i] != b.d[i]) {
+ if (((u8 *)a.d)[i] != ((u8 *)b.d)[i]) {
++i;
break;
}
@@ -67,7 +67,7 @@ Lump_s prefix(Lump_s a, Lump_s b) {
return p;
}
-#define LUMP(_x) (_x).size, (_x).d
+#define LUMP(_x) (_x).size, ((u8 *)(_x).d)
int main (int argc, char *argv[]) {
Lump_s a;
Lump_s b;

0 comments on commit 00ab9af

Please sign in to comment.