Benchmark Bash fastest replace with tr sed awk perl

Test String (10xX):

Test Cases Results must look like:

single char remove:

single char replace:

string/multi char remove:

string/multi char replace:

Times:

run the test string from file 100000 times.

single char remove single char replace multi char remove multi char replace string remove string replace
sed 5.658s 5.774s 3.449s 5.929s 3.476s 5.724s
perl regex 5.604s 5.918s 3.428s 6.027s 3.482s 5.870s
awk gsub 3.469s 5.892s 3.339s 5.942s
tr bash 5.972s 5.897s
perl tr  5.996s  5.837s

 

For bash its the easiest way to use sed because its simpler to use perl and it could do the most things or if you do simple things you could use tr.In perl you could see this benchmark.

SED 4.2.2

single char remove:

single char replace:

multi char remove:

multi char replace:

string remove:

string replace:

 

AWK 4.0.1

single replace with regex not possible.

multi char remove:

multi char replace:

string remove:

string replace:

 

TR 8.21

single replace and remove not possible.

multi char replace:

string replace:

 

PERL REGEX 5

single char remove:

single char replace:

multi char remove:

multi char replace:

string remove:

string replace:

 

PERL TR 5

multi char replace:

string replace:

 

Get the Core temp with lm-sensors

install sensors with:

for the average core temp use this:

and max core temp:

Important is in sed to escape the ‘|’ in regex like ‘|’

Free Ram in Bash

If you want to get the free Ram of your system you could run:

this return free ram in gigabytes :

Check if the value is right :

result :

total       used       free     shared    buffers     cached
Mem:       7573696    6918704     654992          0     362128    5550592
-/+ buffers/cache:    1005984    6567712
Swap:      2540540        480    2540060
654216

seems fine.

CPU Load average in Bash

If you want to use the load average in your Perl-Script you could use this Bash snippets, The load average returns the summary of the last 1,5 and 15 minutes.

This returns the last minute :

How it works : uptime returns all 3 loads, I print with awk the number 10 in the array.then the result is “3,45,” … I remove the last comma with cut and then translate all commas to dots with tr to convert it to a number in Perl.

 

if you want the last 5 minutest you have to change it to :

awk ‘{print $11}’

and for the last 15minutes to :

awk ‘{print $12}’

to check your result run :

result :

12:11:35 up 7 days, 20:20, 2 users, load average: 0,29, 0,35, 0,40
0.29

seems fine.