ProcessSpeed
Summarizes results of Linux time command by parsing time output and converting minutes:seconds format to decimal seconds.
Basic Usage
processspeed.sh <file>
Where <file>
is a text file containing output from the Linux time
command in the format produced by time -p
or similar timing utilities.
Parameters
This tool takes only one positional argument and has no configurable parameters:
Input
- <file>
- Input file containing timing data with lines starting with "real", "user", and "sys" followed by tab-separated time values in minutes:seconds format (e.g., "real\t1m23.456s")
Input Format
The input file should contain timing output from the Linux time
command with lines in this format:
real 1m23.456s
user 0m45.123s
sys 0m12.789s
Each line consists of:
- Label: "real", "user", or "sys"
- Tab separator
- Time value: In format XmY.ZZZs where X is minutes, Y.ZZZ is seconds
Output Format
The tool outputs a header line followed by timing data converted to decimal seconds:
#real user sys
83.456 45.123 12.789
All time values are converted to decimal seconds for easy parsing and analysis.
Examples
Basic Usage
# Run a command with timing
time -p my_program > timing_output.txt
# Process the timing results
processspeed.sh timing_output.txt
This will parse the timing output and display the results in decimal seconds.
Batch Processing Multiple Timing Files
# Process multiple timing files
for file in timing_*.txt; do
echo "Processing $file"
processspeed.sh "$file"
done
Process multiple timing result files to summarize performance data across different runs.
Creating CSV Output
# Create CSV-formatted output for spreadsheet analysis
echo "filename,real,user,sys" > timing_summary.csv
for file in timing_*.txt; do
result=$(processspeed.sh "$file" | tail -1)
echo "$file,$result" >> timing_summary.csv
done
Generate a CSV file with timing summaries from multiple runs for further analysis.
Algorithm Details
ProcessSpeed2 implements a straightforward time parsing algorithm using standard Java I/O classes:
File Processing Implementation
- TextFile-based Reading: Uses TextFile.nextLine() method for sequential file processing with automatic resource management
- String.startsWith() Detection: Identifies timing lines using exact prefix matching ("real\t", "user\t", "sys\t")
- String.split() Extraction: Isolates time values using tab-delimited splitting with split("\t")[1] array indexing
- toSeconds() Method: Custom conversion method implementing string manipulation and arithmetic conversion
Time Conversion Implementation
The toSeconds() method implements this specific algorithm:
- String.replaceAll("s", ""): Removes trailing 's' character using regular expression replacement
- String.split("m"): Separates on 'm' delimiter, creating split[0]=minutes, split[1]=seconds
- Double.parseDouble(): Converts string components to double-precision floating point numbers
- Arithmetic Formula: Calculates 60*minutes + seconds using standard floating-point arithmetic
- Tools.format("%.3f"): Uses BBTools Tools class for 3-decimal formatting with printf-style format specifiers
Output Stream Management
The tool coordinates output through System.out using specific formatting:
- Header Line: System.println("#real\tuser\tsys") writes tab-delimited column headers
- Synchronized Printing: System.print() calls ensure real/user values followed by System.print() with newline for sys
- Tools.format() Precision: Maintains consistent "%.3f\t" and "%.3f\n" format strings for decimal alignment
Use Cases
This utility is particularly useful for:
- Performance Analysis: Converting timing data to machine-readable decimal format for statistical analysis
- Benchmarking: Processing timing results from multiple test runs
- Automation: Integrating timing data collection into automated testing pipelines
- Comparison Studies: Standardizing timing output format for comparison across different tools or parameters
Memory Requirements
ProcessSpeed2 is designed for minimal memory usage:
- Default Memory: 120MB (-Xmx120m) is allocated, which is sufficient for processing timing files of any reasonable size
- Streaming Processing: Reads and processes the input file line-by-line, maintaining constant memory usage regardless of input size
- No Data Accumulation: Does not store processed data in memory, immediately outputting converted values
Error Handling
The tool expects properly formatted input and will encounter issues with:
- Malformed Time Strings: Input not matching the expected XmY.ZZZs format
- Missing Components: Lines lacking proper tab separation or missing time components
- Invalid Numbers: Non-numeric values in the minutes or seconds fields
For best results, ensure input files contain only properly formatted timing output from the Linux time
command.
Related Tools
ProcessSpeed2 is part of the BBTools ecosystem for performance analysis:
- BBTools Performance Utilities: Many BBTools scripts generate timing information that can be processed with this tool
- Benchmarking Scripts: Can be integrated with shell scripts that benchmark BBTools performance
- Statistical Analysis: Output can be fed into statistical analysis tools for performance characterization
Support
For questions and support:
- Email: bbushnell@lbl.gov
- Documentation: bbmap.org