Lubos Rendek

The only solution is determination.

Convert Time Command Output to Seconds

| Comments

Today, I wanted to test my USB flash drive speed with dd command. I have run dd command multiple times with time command and wanted take an average from all results. For example, here is an output of dd and time with 5 times iteration loop:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
$ cat dd-time-out.txt
TEST 1
1800+0 records in
1800+0 records out
1887436800 bytes (1.9 GB) copied, 157.159 s, 12.0 MB/s

real    5m31.014s
user    0m0.004s
sys     0m1.476s
TEST 2
1800+0 records in
1800+0 records out
1887436800 bytes (1.9 GB) copied, 180.861 s, 10.4 MB/s

real    5m41.892s
user    0m0.000s
sys     0m1.908s
TEST 3
1800+0 records in
1800+0 records out
1887436800 bytes (1.9 GB) copied, 174.678 s, 10.8 MB/s

real    5m40.847s
user    0m0.000s
sys     0m1.896s
TEST 4
1800+0 records in
1800+0 records out
1887436800 bytes (1.9 GB) copied, 140.008 s, 13.5 MB/s

real    5m32.853s
user    0m0.012s
sys     0m2.764s
TEST 5
1800+0 records in
1800+0 records out
1887436800 bytes (1.9 GB) copied, 143.161 s, 13.2 MB/s

real    5m37.813s
user    0m0.004s
sys     0m2.484s

The only cosmetic issue is that it would be great to have all times in seconds if one needs to sum up all times and calculate average. Here is one way of solving this problem:

1
2
3
4
5
6
$ cat dd-time-out.txt | grep real | cut -d " " -f5 | sed 's/m/:/' | cut -d \. -f1 | sed s/:/*60+/g | bc
331
341
340
332
337

Now we have times in seconds for each relevant dd output.

Comments