untymage's avatar

Why are my tests is slower than Jeffrey's tests?

OS : Windows 10 Hardware: i7 - 6700k, SSD 850 EVO - 16Gig RAM ENV : Vagrant / PHPStorm

Hello everyone, I'm just wondering at why my tests are slow? Despite the fact that Jeffrey tests with 40 tests and 80 assertion are done in less than 1 seconds (500ms) , But the default laravel test with 1 assertion in my side It takes more than 1 second ? :

Time: 1.63 seconds, Memory: 22.00 MB

OK (1 test, 1 assertion)

Even though I use the sqlite in memory it doesn't have a big impact. Any ideas?

0 likes
3 replies
diegoaurino's avatar
Level 39

Hello, @untymage !

Are you sharing folders between the Vagrant box and Windows?   This slowness is the case when you are sharing folders between different filesystems. There are some things you can do to optimize it, but it will never be as faster than running it on the same filesystem.   The docs for Homestead says the following:  

When using NFS on Windows, you should consider installing the vagrant-winnfsd plug-in. This plug-in will maintain the correct user / group permissions for files and directories within the Homestead box.

  Take a look: https://laravel.com/docs/master/homestead#configuring-homestead   The docs also say to specify the filesystem like:  

folders:
    - map: ~/code
      to: /home/vagrant/code
      type: “nfs”

  So check the plugins available for Vagrant. It will help a little.   If speed is important to you, install PHP directly on Windows to run it locally or put your projects inside the VM and access it remotely or via SSH or Samba share. Microsoft is customizing its own Linux kernel to be used on WSL2; so it will be an option for the future.   For now, a local Windows installation or a customized VM on Hyper-V is the best options.   Let me know if it helps.

1 like
untymage's avatar

@DIEGOAURINO - Yeah thanks, It sounds like the problem was "shared folder", So when we doing TDD we shouldn't initial laravel project in share folder if the "speed" matters right ?

diegoaurino's avatar

@UNTYMAGE - If you are working on projects that require Vagrant, run a single PHPUnit method at a time. Only run the entire suite to check if everything is okay.

Nowadays, I tend to simplify my environment as much as possible. I just use a simple and local PHP installation together with a MySQL server. I also recommend running tests on memory. Thus, when you run your tests, you never touch the MySQL service. For projects that require Unix tools, like Redis, I use it from WSL using the default ports.

If you need to make sure your app is compatible with your deployment machine, you can do that by creating a custom VM on Hyper-V (or VirtualBox) that matches your remote machine. In that case, you have an option to access your files via SSH or Samba. Even better, you can use some tools provide by big IDEs like PHPstorm to access it the same way we did in the old days by uploading via SFTP on save. Set git hooks to upload the files to the VM are also options.

I would stay with the local option. I have a long background in using Linux distributions, but I am very satisfied with Windows nowadays and, in some scenarios, it can be much faster than Linux.

1 like

Please or to participate in this conversation.