Home > Software design >  How to deal with the time data
How to deal with the time data

Time:05-09

the linux command code time <command> | tail -n2, I expect to extract the line of sys time and use time, however,I get this as follows:

time picat slater-6_sat ver2 "0"

the Output is :

winner = 4 with the least cost = 0

CPU time 0.0 seconds.

success

real    0m0.054s
user    0m0.035s
sys     0m0.019s

while when I only input the picat slater-6_sat ver2 "0"

the Output is:

winner = 4 with the least cost = 0

CPU time 0.0 seconds.

success

I expect input time picat slater-6_sat ver2 "0" | tail -n2 ,

the Output is :

user    0m0.035s
sys     0m0.019s

however, the truth is :


success

real    0m0.054s
user    0m0.035s
sys     0m0.019s

I guess the reason is the processor think as time ,so treat picat slater-6_sat ver2 "0"| tail -n2 as the command

how can I solve the problem?

CodePudding user response:

You can try something like this:

(time picat slater-6_sat ver2 "0") > output.txt 2>&1 && tail -2 output.txt

See a similar answer here: Output time to file with unix "time" command, but leave output of command to console

Here's a sample python file:

from time import sleep
for x in range(0,10):
    sleep(0.4)
    print(x)

Now run the file like so:

$ (time python3 test.py) > output.txt 2>&1 && tail -2 output.txt

user    0m0.026s
sys 0m0.004s

Additional resources:

  • Related