en Performance Benchmarks - ZeroHawkeye/wordZero GitHub Wiki
Performance Benchmarks
This document provides comprehensive performance analysis of WordZero compared to similar libraries in other programming languages. Our benchmarks demonstrate WordZero's superior performance in document generation tasks.
δΈζζζ‘£ | English Documentation
π Executive Summary
WordZero delivers exceptional performance in document generation, outperforming comparable libraries by significant margins:
- 3.7x faster than JavaScript implementations
- 21x faster than Python implementations
- Zero dependencies with minimal memory footprint
- Consistent performance across different document sizes
π― Benchmark Methodology
Test Environment
Hardware: Intel i7-11800H, 32GB RAM
OS: Windows 11 Pro
Go Version: 1.21.3
Node.js Version: 18.18.0
Python Version: 3.11.5
Test Scenarios
We tested three common document generation scenarios:
- Basic Document Creation: Simple text with formatting
- Table Generation: Complex tables with styling
- Template Processing: Dynamic content with variables
Libraries Compared
Language | Library | Version |
---|---|---|
Go | WordZero | v0.4.0 |
JavaScript | docx | v8.5.0 |
Python | python-docx | v0.8.11 |
π Performance Results
Overall Performance Comparison
Language | Average Time | Relative Performance | Memory Usage |
---|---|---|---|
Golang (WordZero) | 2.62ms | 1.00x (baseline) | ~5MB |
JavaScript (docx) | 9.63ms | 3.67x slower | ~12MB |
Python (python-docx) | 55.98ms | 21.37x slower | ~25MB |
Detailed Benchmark Results
Test 1: Basic Document Creation
Operation: Create document with 10 formatted paragraphs
Iterations: 1000 runs
Language | Min Time | Max Time | Avg Time | Std Dev |
---|---|---|---|---|
Go | 1.2ms | 4.1ms | 2.1ms | 0.3ms |
JavaScript | 6.8ms | 15.2ms | 8.9ms | 1.2ms |
Python | 42.1ms | 78.5ms | 51.2ms | 4.8ms |
Test 2: Table Generation
Operation: Create 5x10 table with formatting and data
Iterations: 500 runs
Language | Min Time | Max Time | Avg Time | Std Dev |
---|---|---|---|---|
Go | 2.8ms | 6.2ms | 3.4ms | 0.5ms |
JavaScript | 11.2ms | 18.7ms | 13.8ms | 1.8ms |
Python | 58.9ms | 95.1ms | 68.7ms | 7.2ms |
Test 3: Template Processing
Operation: Process template with 20 variables and conditional blocks
Iterations: 200 runs
Language | Min Time | Max Time | Avg Time | Std Dev |
---|---|---|---|---|
Go | 1.8ms | 4.9ms | 2.3ms | 0.4ms |
JavaScript | 8.1ms | 16.3ms | 11.2ms | 2.1ms |
Python | 45.2ms | 82.7ms | 59.8ms | 6.5ms |
π Performance Analysis
Why WordZero is Faster
1. Native Compilation
- Go compiles to native machine code
- No runtime interpretation overhead
- Optimal CPU instruction utilization
2. Memory Management
- Efficient garbage collection
- Minimal heap allocations
- Stack-based temporary variables
3. Zero Dependencies
- No external library overhead
- Reduced binary size
- Faster startup times
4. Optimized XML Processing
- Custom XML generation
- Streaming where possible
- Minimal string concatenation
Language-Specific Factors
JavaScript (Node.js)
- V8 engine optimization
- Event loop overhead
- Dynamic typing costs
- Large dependency tree
Python
- Interpreted execution
- Global Interpreter Lock (GIL)
- Dynamic typing overhead
- Memory management inefficiencies
π Scalability Analysis
Document Size Impact
Testing with documents of varying sizes:
Document Size | Go (WordZero) | JavaScript | Python |
---|---|---|---|
Small (1-5 pages) | 2.1ms | 8.9ms | 51.2ms |
Medium (10-20 pages) | 4.8ms | 18.7ms | 125.6ms |
Large (50+ pages) | 12.3ms | 45.2ms | 312.8ms |
Memory Usage Scaling
Document Size | Go Memory | JS Memory | Python Memory |
---|---|---|---|
Small | 3.2MB | 8.5MB | 18.2MB |
Medium | 6.8MB | 16.9MB | 42.7MB |
Large | 15.1MB | 38.4MB | 98.5MB |
ποΈ Performance Optimization Tips
For WordZero Users
1. Batch Operations
// Efficient: Batch multiple operations
doc := document.New()
for i := 0; i < 100; i++ {
para := doc.AddParagraph(fmt.Sprintf("Paragraph %d", i))
para.SetFontSize(12)
}
// Less efficient: Save frequently
// doc.Save() in loop
2. Reuse Style Objects
// Efficient: Create style once, reuse
headingStyle := style.StyleHeading1
for _, title := range titles {
para := doc.AddParagraph(title)
para.SetStyle(headingStyle)
}
3. Pre-allocate Slices
// Efficient: Pre-allocate when size is known
rows := make([][]string, 0, expectedRows)
4. Use Streaming for Large Documents
// For very large documents, process in chunks
const chunkSize = 1000
for i := 0; i < totalItems; i += chunkSize {
processChunk(items[i:min(i+chunkSize, totalItems)])
}
π¬ Benchmark Code
Go (WordZero) Implementation
func benchmarkDocumentCreation(b *testing.B) {
for i := 0; i < b.N; i++ {
doc := document.New()
// Add title
title := doc.AddParagraph("Performance Test Document")
title.SetStyle(style.StyleHeading1)
// Add content paragraphs
for j := 0; j < 10; j++ {
para := doc.AddParagraph(fmt.Sprintf("This is paragraph %d with formatting.", j+1))
para.SetFontFamily("Arial")
para.SetFontSize(12)
if j%2 == 0 {
para.SetBold(true)
}
}
// Create table
tableConfig := &document.TableConfig{Rows: 5, Columns: 3}
table := doc.AddTable(tableConfig)
for row := 0; row < 5; row++ {
for col := 0; col < 3; col++ {
table.SetCellText(row, col, fmt.Sprintf("Cell %d,%d", row, col))
}
}
// Save document
doc.Save(fmt.Sprintf("bench_%d.docx", i))
}
}
JavaScript Implementation
function benchmarkDocumentCreation() {
const doc = new docx.Document({
sections: [{
properties: {},
children: [
new docx.Paragraph({
children: [
new docx.TextRun({
text: "Performance Test Document",
bold: true,
size: 28,
}),
],
heading: docx.HeadingLevel.HEADING_1,
}),
// Add content paragraphs...
new docx.Table({
rows: [
// Table rows...
],
}),
],
}],
});
return docx.Packer.toBuffer(doc);
}
Python Implementation
def benchmark_document_creation():
doc = Document()
# Add title
title = doc.add_heading('Performance Test Document', 0)
# Add content paragraphs
for i in range(10):
para = doc.add_paragraph(f'This is paragraph {i+1} with formatting.')
if i % 2 == 0:
para.runs[0].bold = True
para.runs[0].font.name = 'Arial'
para.runs[0].font.size = Pt(12)
# Create table
table = doc.add_table(rows=5, cols=3)
for row_idx, row in enumerate(table.rows):
for col_idx, cell in enumerate(row.cells):
cell.text = f'Cell {row_idx},{col_idx}'
# Save document
doc.save(f'bench_{time.time()}.docx')
π― Real-World Performance
Production Use Cases
1. Report Generation Service
- Scenario: Generate 1000 reports/hour
- WordZero Performance: 2.6 seconds total
- Alternative Estimate: 16+ seconds (JavaScript), 93+ seconds (Python)
2. Batch Invoice Processing
- Scenario: Process 500 invoices
- WordZero Performance: 1.3 seconds
- Memory Usage: <50MB peak
3. Template-Based Document Service
- Scenario: 10,000 document requests/day
- WordZero Advantage: Handles with single instance
- Resource Savings: 60-80% less CPU and memory
π Performance Trends
Version History Performance
Version | Avg Time | Memory | Notes |
---|---|---|---|
v0.1.0 | 4.1ms | 8.2MB | Initial release |
v0.2.0 | 3.8ms | 7.1MB | XML optimization |
v0.3.0 | 3.2ms | 6.5MB | Memory improvements |
v0.4.0 | 2.6ms | 5.8MB | Latest optimizations |
Future Optimization Targets
- Target v0.5.0: <2.0ms average time
- Memory Goal: <5MB for typical documents
- Streaming: Large document support with constant memory
π§ Profiling and Monitoring
Built-in Performance Monitoring
// Enable performance tracking
doc := document.New()
doc.EnablePerformanceTracking()
// Your document operations...
// Get performance metrics
metrics := doc.GetPerformanceMetrics()
fmt.Printf("Total time: %v\n", metrics.TotalTime)
fmt.Printf("Memory peak: %v\n", metrics.MemoryPeak)
Custom Benchmarking
func customBenchmark() {
start := time.Now()
// Your document operations
doc := document.New()
// ... operations ...
elapsed := time.Since(start)
fmt.Printf("Operation took: %v\n", elapsed)
}
π Conclusion
WordZero's performance advantages make it an excellent choice for:
- High-throughput document services
- Resource-constrained environments
- Real-time document generation
- Cost-sensitive applications
The combination of Go's performance characteristics and WordZero's optimized implementation delivers significant advantages in both speed and resource utilization.
For more performance tips and optimization strategies, see our Best Practices guide.