compute compilation time using script

Hi,

I use this script to compute compilation time several time to get system performance and compare different system:

#!/bin/sh
# measure the different between time before and
# after the compilation of benchmark

# Start at iteration 1
num=1
while [ $num -le 10 ]
do
# Add one to the iteration number
num=`expr $num + 1`
sec1=`date | cut -c18-19`

gcc benchmark.c

sec2=`date | cut -c18-19`
result=`expr $sec2 - $sec1`

if [ $result -le 0 ]
then
echo The compilation time = 0
else
echo The compilation time = $result
fi

done

the output is compilation time in sec ( which is large):
The compilation time = 1
The compilation time = 0
The compilation time = 1
The compilation time = 0
The compilation time = 1
The compilation time = 1
The compilation time = 0
The compilation time = 1
The compilation time = 0
The compilation time = 1

how to get time in micro or milli second?

appreciate your help...

zainab,

Instead of using like this. why cant you use time function.

For eg :

time gcc benchmark.c

This will return the time taken to execute the program.

you can use

timex programname 

to get the time details

thank you soooooooo much:)