File operation times differ significantly between PHP and Node.js

  node.js, php

I am currently doing some research comparing PHP and Node.js in some respects. I am currently comparing the file operation times and after comparing the graphs for copying and moving files, I must admit that I am a bit surprised.
Let’s see it on the graphs:
enter image description here

As we can see:

  • 15 attempts
  • File 1GB
  • 4GB RAM
  • 2CPUs
  • Same environment

I’m not asking about the times but: Why Node.js moves a file much slower than copies it? What are the causes of such differences?
Below are scripts used for these tests:
PHP Move

$src = sprintf("/tasks/files/file_%s", $size);
$dest = sprintf("/tasks/files/trash/file_%s", $size);

rename($src, $dest);

PHP Copy

$src = sprintf("/tasks/files/file_%s", $size);
$dest = sprintf("/tasks/files/trash/file_%s", $size);

copy($src, $dest);

Node.js Move

const src = `/tasks/files/file_${size}`;
const dest = `/tasks/files/trash/file_${size}`;

fs.renameSync(src, dest, (err) => {
    if (err) {
        throw err
    };
});

Node.js Copy

const src = `/tasks/files/file_${size}`;
const dest = `/tasks/files/trash/file_${size}`;

fs.copyFileSync(src, dest, (err) => {
    if (err) {
        throw err
    };
});

Source: Ask PHP

LEAVE A COMMENT