javascript - 单个函数中 require node.js 模块与全局函数对性能的影响

标签 javascript node.js performance

我有一个包含多个函数的node.js 文件。假设每个函数都需要下划线模块。在每个函数中添加 var underS = require("underscore"); 与声明单个 var underS = require("underscore"); 对性能有何影响> 全局排名第一?哪个性能更好?

最佳答案

Modules are cached after the first time they are loaded. This means (among other things) that every call to require('foo') will get exactly the same object returned, if it would resolve to the same file.

所以基本上不会,不会影响性能。

关于javascript - 单个函数中 require node.js 模块与全局函数对性能的影响,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33853042/

相关文章:

java - 成为绩效顾问的主要技能是什么?

javascript - ajax jquery 和点击事件

node.js - 如何从 Node.js 网络错误中获取更大的堆栈跟踪?

javascript - 使用 Jasmine 或任何其他替代方案在 Node 上运行测试 .mjs/ESM

node.js - 编写查询以从多个值添加键

python - 加速风险 war 游戏掷骰子模拟

java - 增强的 for 循环性能

php - 有哪些方法可以禁用或更正网络应用程序中的向后浏览?

javascript - 浏览器自动填充选项与 Angular Material 自动完成选项重叠

javascript - ng-repeat 非数组/对象/以相同的方式处理数组和非数组