Skip to content

Latest commit

 

History

History
148 lines (107 loc) · 11 KB

File metadata and controls

148 lines (107 loc) · 11 KB

Rust Logging Libraries Benchmark Report

Executive Summary

This report presents benchmark results comparing five Rust logging libraries: tracing, log, loguru, slog, and log4rs. Performance benchmarks measure execution time and throughput across various logging scenarios, including different log levels (DEBUG, ERROR, INFO), payload sizes (from 5 to 10,000 elements), and threading configurations (2, 4, 8, and 16 threads).

Per-Benchmark Comparison

1. Standard Logging Operations

DEBUG Level Logging

Library DEBUG_10 (Mean) DEBUG_10 (Throughput) DEBUG_100 (Mean) DEBUG_100 (Throughput) DEBUG_1000 (Mean) DEBUG_1000 (Throughput)
slog 3.11 ns 321.75 Melem/s 3.03 ns 329.70 Melem/s 3.08 ns 324.96 Melem/s
loguru 161.89 ns 6.18 Melem/s 165.11 ns 6.06 Melem/s 175.00 ns 5.71 Melem/s
log 416.89 ns 2.40 Melem/s 489.20 ns 2.04 Melem/s 1.02 ns 984.46 Kelem/s
tracing 597.46 ns 1.67 Melem/s 626.56 ns 1.60 Melem/s 694.39 ns 1.44 Melem/s

Analysis: For DEBUG level logging, slog demonstrates exceptional performance with the lowest execution times (3.03-3.11 ns) and highest throughput (321-330 Melem/s). loguru follows with consistent performance around 161-175 ns and throughput of 5.7-6.2 Melem/s. Both log and tracing show higher execution times, with log being generally faster than tracing.

ERROR Level Logging

Library ERROR_10 (Mean) ERROR_10 (Throughput) ERROR_100 (Mean) ERROR_100 (Throughput) ERROR_1000 (Mean) ERROR_1000 (Throughput)
slog 5.93 ns 168.77 Melem/s 5.90 ns 169.47 Melem/s 5.92 ns 168.96 Melem/s
loguru 170.28 ns 5.87 Melem/s 165.84 ns 6.03 Melem/s 177.68 ns 5.63 Melem/s
log 426.14 ns 2.35 Melem/s 484.02 ns 2.07 Melem/s 1.01 ns 985.72 Kelem/s
tracing 649.43 ns 1.54 Melem/s 608.77 ns 1.64 Melem/s 627.64 ns 1.59 Melem/s

Analysis: For ERROR level logging, the pattern is similar to DEBUG level. slog maintains superior performance with consistent execution times around 5.9 ns. loguru shows consistent execution times around 165-178 ns. log and tracing again have higher execution times, with log outperforming tracing in most cases.

INFO Level Logging (Various Payload Sizes)

Library INFO_5 (Mean) INFO_10 (Mean) INFO_100 (Mean) INFO_1000 (Mean) INFO_10000 (Mean)
slog 574.05 ns 5.92 ns 463.86 ns 4.84 ns 46.44 ns
loguru 1.06 ns 161.89 ns 16.47 ns 173.04 ns 1.69 ms
log 596.44 ns 437.14 ns 51.97 ns 520.98 ns 5.24 ms
tracing 1.35 ns 606.80 ns 61.91 ns 620.66 ns 6.15 ms
Library INFO_5 (Throughput) INFO_10 (Throughput) INFO_100 (Throughput) INFO_1000 (Throughput) INFO_10000 (Throughput)
slog 1.74 Melem/s 168.80 Melem/s 215.58 Melem/s 206.61 Melem/s 215.35 Melem/s
loguru 944.46 Kelem/s 6.18 Melem/s 6.07 Melem/s 5.78 Melem/s 5.91 Melem/s
log 1.68 Melem/s 2.29 Melem/s 1.92 Melem/s 1.92 Melem/s 1.91 Melem/s
tracing 739.97 Kelem/s 1.65 Melem/s 1.62 Melem/s 1.61 Melem/s 1.63 Melem/s

Analysis: For INFO level logging with varying payload sizes, we see interesting patterns. slog shows high variability in execution times but maintains excellent throughput across all payload sizes. loguru demonstrates more consistent performance across different payload sizes, especially for throughput. For large payloads (INFO_10000), execution times increase significantly across all libraries, with slog maintaining the best relative performance.

2. Concurrent Logging (Multiple Threads)

Library INFO_2_threads (Mean) INFO_4_threads (Mean) INFO_8_threads (Mean) INFO_16_threads (Mean)
slog 118.84 ns 231.05 ns 358.89 ns 677.73 ns
loguru 153.81 ns 265.08 ns 450.35 ns 926.81 ns
log 201.21 ns 329.56 ns 488.69 ns 1.02 ms
tracing 209.70 ns 382.74 ns 520.05 ns 1.03 ms
Library INFO_2_threads (Throughput) INFO_4_threads (Throughput) INFO_8_threads (Throughput) INFO_16_threads (Throughput)
slog 1.68 Melem/s 1.73 Melem/s 2.23 Melem/s 2.36 Melem/s
loguru 1.30 Melem/s 1.51 Melem/s 1.78 Melem/s 1.73 Melem/s
log 993.98 Kelem/s 1.21 Melem/s 1.64 Melem/s 1.56 Melem/s
tracing 953.74 Kelem/s 1.05 Melem/s 1.54 Melem/s 1.55 Melem/s

Analysis: For concurrent logging, execution times increase with the number of threads across all libraries. slog maintains the best performance throughout, with the lowest execution times and highest throughput. Interestingly, slog shows improved throughput as thread count increases, suggesting good scalability. loguru follows with the second-best performance overall, maintaining reasonable execution times even at higher thread counts.

3. File Rotation Performance

Library File Rotation (Mean) File Rotation (Throughput)
slog 7.08 ms 1.41 Melem/s
tracing 16.65 ms 600.60 Kelem/s
log4rs 32.73 ms 305.49 Kelem/s
loguru 48.05 ms 208.13 Kelem/s

Analysis: For file rotation, slog demonstrates superior performance with the lowest execution time (7.08ms) and highest throughput (1.41 Melem/s). tracing follows with moderate performance. log4rs, which specializes in file operations, shows midrange performance. loguru has the highest execution time and lowest throughput for file rotation operations, indicating this as a potential area for optimization.

Detailed Performance Metrics

Performance by Category

Standard Logging Performance (Mean Execution Time)

slog loguru log tracing
DEBUG 🟢 1st 🟡 2nd 🟠 3rd 🔴 4th
ERROR 🟢 1st 🟡 2nd 🟠 3rd 🔴 4th
INFO 🟢 1st* 🟡 2nd 🟠 3rd 🔴 4th

*With some variability depending on payload size

Throughput Performance (elements/second)

slog loguru log tracing
DEBUG 🟢 1st 🟡 2nd 🟠 3rd 🔴 4th
ERROR 🟢 1st 🟡 2nd 🟠 3rd 🔴 4th
INFO 🟢 1st 🟡 2nd 🟠 3rd 🔴 4th

Concurrent Performance (Mean Execution Time)

slog loguru log tracing
2 Threads 🟢 1st 🟡 2nd 🟠 3rd 🔴 4th
4 Threads 🟢 1st 🟡 2nd 🟠 3rd 🔴 4th
8 Threads 🟢 1st 🟡 2nd 🟠 3rd 🔴 4th
16 Threads 🟢 1st 🟡 2nd 🟠 3rd 🔴 4th

File Rotation Performance

slog tracing log4rs loguru
Execution 🟢 1st 🟡 2nd 🟠 3rd 🔴 4th
Throughput 🟢 1st 🟡 2nd 🟠 3rd 🔴 4th

Position of rust-loguru

rust-loguru demonstrates solid performance characteristics in this benchmark suite:

  1. Strengths:

    • Consistently ranks 2nd in performance across all test categories
    • Excellent throughput for standard logging operations (5.6-6.2M elements/second), significantly outperforming both tracing and log
    • Consistent execution times across different log levels and payload sizes
    • Good multithreading efficiency with competitive performance across thread counts
    • Very low execution times for standard operations (~160-177ns) compared to log and tracing
    • Shows excellent stability across test parameters with minimal variability
  2. Areas for Improvement:

    • File rotation performance (48.05ms) is the slowest among all tested libraries, about 6.8× slower than slog
    • While faster than log and tracing, rust-loguru is still significantly slower than slog for most operations
    • For INFO_5 and INFO_100 operations, shows some variability in execution time that differs from its otherwise consistent pattern
  3. Competitive Positioning:

    • rust-loguru ranks 2nd in standard logging performance after slog
    • For applications prioritizing consistent logging speed over absolute performance, rust-loguru offers a compelling balance
    • For applications where file rotation is frequent, other libraries may be more suitable

Conclusion

The benchmark results reveal distinct performance characteristics among Rust logging libraries. slog demonstrates exceptional performance in nearly all metrics but may have trade-offs in usability or features not captured in these benchmarks. rust-loguru offers a strong balance of performance and consistency, placing it as a competitive option particularly for applications where standard logging operations are the primary concern.

For developers choosing a logging library, these benchmarks suggest:

  1. For maximum performance: slog
  2. For balanced performance with consistent behavior: loguru
  3. For applications with heavy file rotation requirements: slog or tracing