nodejs测试: buffer和字符串相加对比测试
来源:互联网 发布:commvault备份软件 编辑:程序博客网 时间:2024/06/06 05:10
看到jsconf2010.pdf写的关于buffer对象和string字符串相加的对比图表。发现buffer对象响应的变化很大,眼见为实,因此证实一下:
准备:
apache ab模拟并发,编写两份代码
os: debian 6.0
cpu: Intel(R) Core(TM)2 Duo CPU E8400 @ 3.00GHz
mem: 4G
代码:
var http = require('http'), string = '', buffer='';for(i = 0; i < 16*1024; i++) { string +='d';}var server = http.createServer( function(req, res) { res.writeHead(200); res.end(string, 'ascii'); });server.listen(1339, '127.0.0.1');buffer = new Buffer(16*1024);for(i=0; i < buffer.length; i++) { buffer[i] = 100;}var server2 = http.createServer( function(req, res) { res.writeHead(200); res.end(buffer); });server2.listen(1340, '127.0.0.1');console.log('running');
说明:定义两个监听,实现不同的字符串拼接,并监听不同的端口,方便测试。
运行:
/usr/mytools/httpd/bin/ab -c 300 -n 10000 http://127.0.0.1:1339/usr/mytools/httpd/bin/ab -c 300 -n 10000 http://127.0.0.1:1340结果:
madding@wmmad:~$ /usr/mytools/httpd/bin/ab -c 300 -n 10000 http://127.0.0.1:1339/This is ApacheBench, Version 2.3 <$Revision: 655654 {1}gt;Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/Licensed to The Apache Software Foundation, http://www.apache.org/Benchmarking 127.0.0.1 (be patient)Completed 1000 requestsCompleted 2000 requestsCompleted 3000 requestsCompleted 4000 requestsCompleted 5000 requestsCompleted 6000 requestsCompleted 7000 requestsCompleted 8000 requestsCompleted 9000 requestsCompleted 10000 requestsFinished 10000 requestsServer Software: Server Hostname: 127.0.0.1Server Port: 1339Document Path: /Document Length: 16384 bytesConcurrency Level: 300Time taken for tests: 3.602 secondsComplete requests: 10000Failed requests: 0Write errors: 0Total transferred: 164220000 bytesHTML transferred: 163840000 bytesRequests per second: 2776.02 [#/sec] (mean)Time per request: 108.068 [ms] (mean)Time per request: 0.360 [ms] (mean, across all concurrent requests)Transfer rate: 44519.36 [Kbytes/sec] receivedConnection Times (ms) min mean[+/-sd] median maxConnect: 0 36 326.6 0 3008Processing: 1 47 29.8 46 570Waiting: 1 47 29.8 46 570Total: 1 83 328.9 46 3094Percentage of the requests served within a certain time (ms) 50% 46 66% 60 75% 68 80% 72 90% 81 95% 90 98% 141 99% 3033 100% 3094 (longest request)madding@wmmad:~$ /usr/mytools/httpd/bin/ab -c 300 -n 10000 http://127.0.0.1:1340/This is ApacheBench, Version 2.3 <$Revision: 655654 {1}gt;Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/Licensed to The Apache Software Foundation, http://www.apache.org/Benchmarking 127.0.0.1 (be patient)Completed 1000 requestsCompleted 2000 requestsCompleted 3000 requestsCompleted 4000 requestsCompleted 5000 requestsCompleted 6000 requestsCompleted 7000 requestsCompleted 8000 requestsCompleted 9000 requestsCompleted 10000 requestsFinished 10000 requestsServer Software: Server Hostname: 127.0.0.1Server Port: 1340Document Path: /Document Length: 16384 bytesConcurrency Level: 300Time taken for tests: 1.167 secondsComplete requests: 10000Failed requests: 0Write errors: 0Total transferred: 164220000 bytesHTML transferred: 163840000 bytesRequests per second: 8565.63 [#/sec] (mean)Time per request: 35.024 [ms] (mean)Time per request: 0.117 [ms] (mean, across all concurrent requests)Transfer rate: 137368.00 [Kbytes/sec] receivedConnection Times (ms) min mean[+/-sd] median maxConnect: 0 0 0.9 0 9Processing: 0 16 12.5 15 611Waiting: 0 15 12.4 15 610Total: 1 16 12.5 15 612Percentage of the requests served within a certain time (ms) 50% 15 66% 19 75% 21 80% 23 90% 26 95% 30 98% 33 99% 37 100% 612 (longest request)说明:在300个并发,10000个请求下,采用buffer方式构造对象的性能优化是和之前的3倍以上。
- nodejs测试: buffer和字符串相加对比测试
- C#、PHP与NodeJs性能测试对比
- Nodejs的测试和测试驱动开发
- nodejs 和 swoole 简单测试
- P8700和T9600对比测试
- PHP4和PHP5性能测试和对比
- String和StringBuilder进行大量字符串连接操作时间对比测试
- 自动化测试和手工测试的应用场合对比
- web端测试和移动端测试的对比
- UT测试框架cxxtest和gtest对比
- SQLITE和ACCESS性能对比测试
- Graphics和BufferedGraphicsContext 效率测试对比
- nginx和apache并发性能测试对比
- Redis和Memcache性能测试对比
- Java测试框架TestNG和JUnit对比
- lua 和 luajit 性能对比测试
- php中isset和array_key_exists测试对比
- ArrayList和LinkedList性能对比测试
- Activity生命周期的学习以及Logcat的使用 (五)
- return和 exit的区别
- Oracle 索引组织表(IOT)
- 查看PL/SQL编译时的错误信息
- Java设计模式圣经连载(05)-代理模式
- nodejs测试: buffer和字符串相加对比测试
- 基于多核平台的实时动态体积云模拟
- Hardware Buffers
- JavaScript prototype, 扩充String对象
- HTTP 500 - 内部服务器错误 之三步解决方案
- —— Activity间数据传输 (六)
- 你或许该这样生活
- 主流报表制作工具之王者争夺战:功能大PK系列之动态参数
- c/c++: 多线程编程基础讲解(四)