tomaok
Posts: 2
Joined: Wed Dec 05, 2012 7:31 pm

[SOLVED]Measure execution time inside Shell script

Fri Dec 20, 2013 11:16 am

Hi world,

I 've a problem with using the time program inside a Shell script.
On command line its working well an d give me the execution time of my code.
But inside Shell script :

./test2.sh: time: not found

whereis time ? it gives me nothing see below!
[email protected] ~ $ whereis time
time: /usr/include/time.h /usr/share/man/man7/time.7.gz /usr/share/man/man2/time.2.gz

"FIND" gives me this ??
[email protected] ~ $ sudo find / -name time
/sys/module/printk/parameters/time

So who knows whereis "time" ? an alias toward another program ??

But perhaps you have a better way to measure execution time (in ms please)inside a Shell script ??

Thank you for any help

Tom Aok
Last edited by tomaok on Fri Dec 20, 2013 9:12 pm, edited 1 time in total.

scrapheap
Posts: 20
Joined: Wed Feb 13, 2013 5:13 pm

Re: Measure execution time inside Shell script

Fri Dec 20, 2013 2:25 pm

Sometimes the time command isn't present in the filesystem, instead some OSs choose to rely on bash's builtin in commands. Check if your shell script is set to use bash or something else? Specifically check the first line and if it says:

Code: Select all

#!/bin/sh
Then change it to:

Code: Select all

#!/bin/bash
and see if it makes a difference.

tomaok
Posts: 2
Joined: Wed Dec 05, 2012 7:31 pm

[SOLVED]Re: Measure execution time inside Shell script

Fri Dec 20, 2013 9:11 pm

Wonderfull

it works with #!/bin/bash

Thank you very much

:D

Return to “Other programming languages”