bluebird还有替代原生 promise的必要吗?
2018-01-10 14:52
471 查看
测试代码
// global.Promise = require('bluebird').Promise; console.log('node version:',process.version); const co = require('co'); function* testfun_co(){ let total = 0; for(let i = 0;i<10000;i++){ total += yield done=>done(null,i); } console.log('total:',total); } co(function*(){ console.time('bench origin'); yield *testfun_co(); yield *testfun_co(); console.timeEnd('bench origin'); }).then(ret=>console.log('all test end'));
两个版本的node 测试结果
v8.9.4
// 8.9.4 原生的Promise ➜ bin node "/Users/mac/Documents/testnodejs/pathtest2.js" node version: v8.9.4 total: 49995000 total: 49995000 bench origin: 23.947ms all test end ➜ bin node "/Users/mac/Documents/testnodejs/pathtest2.js" node version: v8.9.4 total: 49995000 total: 49995000 bench origin: 24.263ms all test end // 8.9.4 bluebird ➜ bin node "/Users/mac/Documents/testnodejs/pathtest2.js" node version: v8.9.4 total: 49995000 total: 49995000 bench origin: 43.253ms all test end ➜ bin node "/Users/mac/Documents/testnodejs/pathtest2.js" node version: v8.9.4 total: 49995000 total: 49995000 bench origin: 42.724ms all test end
v6.12.3
// 原生 Promise ➜ bin ./node /Users/mac/Documents/testnodejs/pathtest2.js node version: v6.12.3 total: 49995000 total: 49995000 bench origin: 56.907ms all test end ➜ bin ./node /Users/mac/Documents/testnodejs/pathtest2.js node version: v6.12.3 total: 49995000 total: 49995000 bench origin: 53.840ms all test end // blubird ➜ bin ./node /Users/mac/Documents/testnodejs/pathtest2.js node version: v6.12.3 total: 49995000 total: 49995000 bench origin: 39.129ms all test end ➜ bin ./node /Users/mac/Documents/testnodejs/pathtest2.js node version: v6.12.3 total: 49995000 total: 49995000 bench origin: 38.773ms all test end
对于8.x版本的node,可能只有
promisify还有用?
不过 node8.0加入了一个新API
util.promisify..
还在使用老版本node的同学可以继续用bluebird以提升性能
相关文章推荐
- 利用bluebird的promise 实现nodejs http下载异步调用的同步逻辑
- Android 跳过开机界面 直接软件自启动 Android做自己的桌面 替代原生桌面 Android开发自己桌面
- 原生JS实现Promise
- PHP 原生 Session 类库,可完全替代 CI 自己的 Session 类库 [库 Library] [2.0.x]
- 升级Win10系统后使用其杀软defender还有必要使用360安全卫士等其他杀毒软件吗?
- Python有了asyncio和aiohttp在爬虫这类型IO任务中多线程/多进程还有存在的必要吗?
- Android开发者的担心:PhoneGap替代Android原生?
- Nodejs-使用 promise 替代回调函数
- 原生promise
- Crosswalk集成到Android Studio,替代原生WebView遇到的问题
- Async/Await替代Promise的6个理由
- Neo4j 3.2版正式发布:企业级扩展性增强、原生性能提高,还有更多特性
- 还有没有必要继续再学oracle
- 用promise封装原生ajax请求
- Bluebird-NodeJs的Promise
- 原生javascript替代AJAX
- js原生的url操作函数,及使用方法。(附:下边还有jquery对url里的中文解码函数)
- Bluebird-NodeJs的Promise
- LINQ技术、EF技术都出来蛮久了,软件开发者、软件公司是否还有必要有自己的代码生成器?
- LINQ技术、EF技术都出来蛮久了,软件开发者、软件公司是否还有必要有自己的代码生成器?