fs.readFileSync seems faster than fs.readFile - is it OK to use for a web app in production?

前端 未结 5 1054
难免孤独
难免孤独 2020-12-05 13:19

I know that when developing in node, you should always try to avoid blocking (sync) functions and go with async functions, however I a little test to see how they compare.

5条回答
  •  囚心锁ツ
    2020-12-05 13:40

    After a lot of time and a lot of learn & practice I've tried once more and I've found the answer and I can show some example:

    const fs = require('fs');
    
    const syncTest = () => {
        let startTime = +new Date();
        const results = [];
        const files = [];
    
        for (let i=0, len=4; i {
        let startTime = +new Date();
        const results = [];
        const files = [];
    
        for (let i=0, len=4; i files.push(file));
        };
    
        for (let i=0, len=360; i

提交回复
热议问题