Track Time Taken to Extract Each File in Unrar

While the standard unrar command-line utility does not include a native flag to benchmark individual file extractions, you can accurately track the duration for each file using output piping or wrapper scripts. This guide details how to calculate and display the exact extraction time per file on Linux, macOS, and Windows using incremental timestamping tools and shell loops.

Method 1: Using ts from moreutils (Linux & macOS)

The fastest and least intrusive method is piping the standard output of unrar into ts (part of the moreutils package). The -i flag prints the incremental time elapsed since the previous line of output was displayed.

  1. Install moreutils if it is not already installed:

    • Ubuntu/Debian: sudo apt-get install moreutils
    • macOS (Homebrew): brew install moreutils
  2. Run the extraction command with ts -i:

unrar x archive.rar | ts -i "%.s s"

Because unrar prints each filename upon extraction, ts -i prefixes each line with the exact number of seconds (with millisecond precision) that elapsed while decompressing that specific item.


Method 2: Extracting Sequentially via a Bash Loop

If you require precise millisecond benchmarking without archive header overhead influencing the timestamps, you can list the archive contents and extract each file individually using a Bash loop:

unrar lb archive.rar | while IFS= read -r file; do
    start=$(date +%s%N)
    unrar x -inul archive.rar "$file"
    end=$(date +%s%N)
    duration=$(( (end - start) / 1000000 ))
    echo "Extracted: $file | Time: ${duration} ms"
done
  • unrar lb archive.rar outputs bare file paths inside the archive.
  • -inul suppresses unrar's default console output to keep the log clean.
  • date +%s%N captures the system clock at nanosecond resolution before and after each extraction operation.

Method 3: Using PowerShell (Windows)

On Windows systems, you can achieve per-file timing using PowerShell's built-in Measure-Command cmdlet:

$files = & unrar lb archive.rar
foreach ($file in $files) {
    $time = Measure-Command {
        & unrar x -inul archive.rar "$file"
    }
    [PSCustomObject]@{
        File = $file
        Milliseconds = [math]::Round($time.TotalMilliseconds, 2)
    }
}

This script reads the internal file list, executes the extraction for each entry separately, and outputs a formatted table showing the file name alongside its extraction duration in milliseconds.