The Cookie Machine - Click here to drag window

DUMMY TEXT - Real text set in assets/js/theCookieMachine.js

Views: 7,054β€…    Votes:  3β€…
Tags: bash   benchmarks  
Link: πŸ” See Original Question on Ask Ubuntu πŸ”—

Title: How to interpret time "real", "user" and "sys"
ID: /2017/06/01/How-to-interpret-time-_real__-_user_-and-_sys_
Created: June 1, 2017    Edited:  June 1, 2017
Upload: November 24, 2022    Layout:  post
TOC: false    Navigation:  false    Copy to clipboard:  false


I’ve been fine-tuning code to reduce processing from 30 seconds to under a second in various parts of my bash program. I’m having trouble wrapping my mind about how the time command works when it reports real, user and sys variables.

I have this code:

echo " "
echo "Time to build DirsNdxArr from DirsArr $DirsArrCnt elements:"
time for (( i=1; i<$DirsArrCnt; i=i+$DaElementCnt )); do
    AllItemSizes=$(( $AllItemSizes + ${DirsArr[$(( $i + $ColFileSizes - 1 ))]} ))

echo " "
echo "Time to build FilesNdxArr from FilesArr $FilesArrCnt elements:"
time for (( i=0; i<$FilesArrCnt; i=i+$FaElementCnt )); do
    AllTagSizes=$(( $AllTagSizes + ${FilesArr[$(( $i + $FaColFileSizes ))]} ))

That reports this:

Time to build DirsNdxArr from DirsArr 56700 elements:

real	0m0.149s
user	0m0.149s
sys 	0m0.000s
Time to build FilesNdxArr from FilesArr 390 elements:

real	0m0.002s
user	0m0.002s
sys  	0m0.000s

Why is sys time reporting zero?

Interpreting the output of time builtin command one would assume the system is doing nothing but surely this isn’t what is happening?

ps I know \n can be used as a new-line to echo with -e parameter. My habit is to sacrifice one liner-cuteness and fringe arguments in favor of readability.

⇧ Backup Linux configuration, scripts and documents to Gmail Changing processor  β‡©