Thursday, April 11, 2019

Powershell vs Golang: what is better?



Hi, everyone.

In this post, I want to share my opinion and result of the test which compares PowerShell with golang.




Prehistory

Unfortunately, the company where I am working use old technology. Managers don't care about benefits and saving money by using new technologies. We still use PowerShell scripts in 2019 years in almost all our tasks.

Recently we wrote a script for the following tasks:

We have one directory, which contains more than 10 000 files.

The size of this directory 20 GB.

We have an array of masks, which we should keep.

Other files should be removed.

For example:
Folder A
|----->Folder A1
|----->Folder A2
Folder B
|----->Folder B1
|----->Folder B2
Folder C
Let's say that we need keep files in folders A1 and B2.
In this case our script should process and remove only folders A2, B1 and C.

Measuring


Go back to our task. We wrote a script in PowerShell.

We found that:


  •  60% is measuring what should we remove
  •  25% collect structure of  folders
  • 15% removing operation.


As you can see, that processing an array of folders take a long time.
This script process 10 000 files for almost 2 minutes.

Create better performance


In my work, we haven't microservices.
We haven't kubernetes, and we don't write operators on golang.
But on someday, I decided to write the same script in golang.
I was in a shock: the same script in the golang work only 20 seconds!
It was an amazing result.
Later we become rewriting our custom tasks to golang.
In different tasks, we decrease execution time from 5-80% times!


Conclusion


As far as I understand Microsoft Powershell loading modules during some execution.

Every operation increase time with few milliseconds or even seconds.
It creates bad performance.
If you still not sure if golang faster than PowerShell just do a small task:
print in PowerShell and golang "Hello world" one million times.
And measure this time execution.
Feel free to write comments about your experience!






No comments:

Post a Comment