Add bench.html to display benchmark data

This commit is contained in:
c9s 2014-05-16 18:33:48 +08:00
parent 046ec9e977
commit 869e8c6d01
2 changed files with 143 additions and 7 deletions

126
bench.html Normal file
View file

@ -0,0 +1,126 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Benchmark</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/data.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<script>
$.get('tests/bench_str.csv', function(data) {
$('#container').highcharts({
data: {
csv: data,
parseDate: function (s) {
console.log( arguments );
var match = s.match(/^([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{2})$/);
if (match) {
return Date.UTC(+('20' + match[3]), match[1] - 1, +match[2]);
}
}
},
title: {
text: 'Daily visits at www.highcharts.com'
},
subtitle: {
text: 'Source: Google Analytics'
},
xAxis: {
type: 'datetime',
tickInterval: 7 * 24 * 3600 * 1000, // one week
tickWidth: 0,
gridLineWidth: 1,
labels: {
align: 'left',
x: 3,
y: -3
}
},
yAxis: [{ // left y axis
title: {
text: null
},
labels: {
align: 'left',
x: 3,
y: 16,
format: '{value:.,0f}'
},
showFirstLabel: false
}, { // right y axis
linkedTo: 0,
gridLineWidth: 0,
opposite: true,
title: {
text: null
},
labels: {
align: 'right',
x: -3,
y: 16,
format: '{value:.,0f}'
},
showFirstLabel: false
}],
legend: {
align: 'left',
verticalAlign: 'top',
y: 20,
floating: true,
borderWidth: 0
},
tooltip: {
shared: true,
crosshairs: true
},
plotOptions: {
series: {
cursor: 'pointer',
point: {
events: {
click: function (e) {
hs.htmlExpand(null, {
pageOrigin: {
x: e.pageX,
y: e.pageY
},
headingText: this.series.name,
maincontentText: Highcharts.dateFormat('%A, %b %e, %Y', this.x) +':<br/> '+
this.y +' visits',
width: 200
});
}
}
},
marker: {
lineWidth: 1
}
}
},
series: [{
name: 'Speed',
lineWidth: 4,
marker: {
radius: 4
}
}]
});
});
</script>
</head>
<body>
<div id="container" style="width: 800px; height: 400px; margin: 0 auto"></div>
</body>
</html>

View file

@ -10,6 +10,16 @@
#define MICRO_IN_SEC 1000000.00
#define SEC_IN_MIN 60
#define NUL '\0'
long unixtime() {
struct timeval tp;
long sec = 0L;
if (gettimeofday((struct timeval *) &tp, (NUL)) == 0) {
return tp.tv_sec;
}
return 0;
}
double microtime() {
struct timeval tp;
long sec = 0L;
@ -218,30 +228,30 @@ START_TEST (test_route_split)
t = split_route_pattern("/blog", strlen("/blog") );
fail_if( t == NULL );
str_array_dump(t);
// str_array_dump(t);
str_array_free(t);
t = split_route_pattern("/foo/{id}", strlen("/foo/{id}") );
fail_if( t == NULL );
str_array_dump(t);
// str_array_dump(t);
fail_if( t->len != 2 );
str_array_free(t);
t = split_route_pattern("/foo/bar/{id}", strlen("/foo/bar/{id}") );
fail_if( t == NULL );
str_array_dump(t);
// str_array_dump(t);
fail_if( t->len != 3 );
str_array_free(t);
t = split_route_pattern("/{title}", strlen("/{title}") );
fail_if( t == NULL );
str_array_dump(t);
// str_array_dump(t);
fail_if( t->len != 1 );
str_array_free(t);
t = split_route_pattern("/", strlen("/") );
fail_if( t == NULL );
str_array_dump(t);
// str_array_dump(t);
fail_if( t->len != 1 );
str_array_free(t);
@ -632,11 +642,11 @@ START_TEST(benchmark_str)
}
double e = microtime();
printf("%.2f i/sec\n", e - s / N );
printf("%.2f i/sec\n", N / (e - s) );
printf("%lf seconds\n", e - s );
FILE *fp = fopen("bench_str.csv", "a+");
fprintf(fp, "%.2f,\"%s\"\n", e - s / N, "using strcmp" );
fprintf(fp, "%ld,%.2f\n", unixtime(), N / (e - s));
fclose(fp);
}