File tree Expand file tree Collapse file tree 5 files changed +96
-1
lines changed
Expand file tree Collapse file tree 5 files changed +96
-1
lines changed Original file line number Diff line number Diff line change 1+ function next ( i ) {
2+ if ( i <= 0 ) return ;
3+
4+ var process = node . createProcess ( "echo hello" ) ;
5+
6+ process . addListener ( "output" , function ( chunk ) {
7+ if ( chunk ) print ( chunk ) ;
8+ } ) ;
9+
10+ process . addListener ( "exit" , function ( code ) {
11+ if ( code != 0 ) node . exit ( - 1 ) ;
12+ next ( i - 1 ) ;
13+ } ) ;
14+ }
15+
16+ next ( 500 ) ;
Original file line number Diff line number Diff line change 1+ var benchmarks = [ "static_http_server.js"
2+ , "timers.js"
3+ , "process_loop.js"
4+ ] ;
5+
6+ var benchmark_dir = node . path . dirname ( __filename ) ;
7+
8+ function exec ( script , callback ) {
9+ var command = ARGV [ 0 ] + " " + node . path . join ( benchmark_dir , script ) ;
10+ var start = new Date ( ) ;
11+ var process = node . createProcess ( command ) ;
12+ process . addListener ( "exit" , function ( code ) {
13+ var elapsed = new Date ( ) - start ;
14+ callback ( elapsed , code ) ;
15+ } ) ;
16+ }
17+
18+ function runNext ( i ) {
19+ if ( i >= benchmarks . length ) return ;
20+ print ( benchmarks [ i ] + ": " ) ;
21+ exec ( benchmarks [ i ] , function ( elapsed , code ) {
22+ if ( code != 0 ) {
23+ puts ( "ERROR " ) ;
24+ }
25+ puts ( elapsed ) ;
26+ runNext ( i + 1 ) ;
27+ } ) ;
28+ } ;
29+ runNext ( 0 ) ;
Original file line number Diff line number Diff line change 1+ var concurrency = 30 ;
2+ var nrequests = 700 ;
3+ var port = 8000 ;
4+ var completed_requests = 0 ;
5+ var bytes = 1024 * 5 ;
6+
7+ var body = "" ;
8+ for ( var i = 0 ; i < bytes ; i ++ ) {
9+ body += "C" ;
10+ }
11+
12+ var server = node . http . createServer ( function ( req , res ) {
13+ res . sendHeader ( 200 , [
14+ [ "Content-Type" , "text/plain" ] ,
15+ [ "Content-Length" , body . length ]
16+ ] ) ;
17+ res . sendBody ( body ) ;
18+ res . finish ( ) ;
19+ } )
20+ server . listen ( port ) ;
21+
22+ function responseListener ( res ) {
23+ res . addListener ( "complete" , function ( ) {
24+ //puts("response " + completed_requests + " from client " + res.client.id);
25+ if ( completed_requests ++ < nrequests ) {
26+ res . client . get ( "/" ) . finish ( responseListener ) ;
27+ } else {
28+ server . close ( ) ;
29+ }
30+ } ) ;
31+ }
32+
33+ function onLoad ( ) {
34+ for ( var i = 0 ; i < concurrency ; i ++ ) {
35+ var client = node . http . createClient ( port ) ;
36+ client . id = i ;
37+ client . get ( "/" ) . finish ( responseListener ) ;
38+ }
39+ }
Original file line number Diff line number Diff line change 1+ function next ( i ) {
2+ if ( i <= 0 ) return ;
3+ setTimeout ( function ( ) { next ( i - 1 ) ; } , 1 ) ;
4+ }
5+ next ( 700 ) ;
Original file line number Diff line number Diff line change @@ -100,6 +100,12 @@ test: all
100100test-all: all
101101 python tools/test.py --mode=debug,release
102102
103+ test-debug: all
104+ python tools/test.py --mode=release,debug
105+
106+ benchmark: all
107+ build/default/node benchmark/run.js
108+
103109website: website/api.html website/index.html
104110
105111website/api.html: website/api.txt
@@ -123,7 +129,7 @@ check:
123129dist:
124130 @$WAF dist
125131
126- .PHONY: clean dist distclean check uninstall install all test test-all website website-upload
132+ .PHONY: benchmark clean dist distclean check uninstall install all test test-all website website-upload
127133
128134EOF
129135}
You can’t perform that action at this time.
0 commit comments