Last active
August 10, 2025 02:51
-
-
Save zfogg/94e92bbc3f38f9a5eb216c8c34b5d160 to your computer and use it in GitHub Desktop.
compare ascii-chat's data's bandwidth usage to 1080p video
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import zlib | |
| width = 203 | |
| height = 64 | |
| fps = 60 # 60 fps | |
| # Test different scenarios | |
| scenarios = [] | |
| # 1. Best case - mostly spaces and simple patterns | |
| simple_frame = (' ' * width + '\n') * (height // 2) + ('=' * width + '\n') * (height // 2) | |
| scenarios.append(("Simple/static", simple_frame)) | |
| # 2. Typical ASCII art - mix of characters | |
| typical = [] | |
| chars = " .'`^\",:;Il!i><~+_-?][}{1)(|/tfjrxnuvczXYUJCLQ0OZmwqpdbkhao*#MW&8%B@$" | |
| for y in range(height): | |
| row = ''.join(chars[(x+y*2) % len(chars)] for x in range(width)) | |
| typical.append(row) | |
| scenarios.append(("Typical ASCII art", '\n'.join(typical))) | |
| # 3. Colored with smart optimization (only change color when needed) | |
| colored = [] | |
| for y in range(height): | |
| row = [] | |
| for x in range(width): | |
| # Only add color codes every ~20 chars (when color actually changes) | |
| if x % 20 == 0: | |
| # Average ANSI code is ~14 bytes: \033[38;2;RRR;GGG;BBBm | |
| row.append(f"\033[38;2;{100+x%155};{100+y%155};{150}m") | |
| row.append(chars[(x+y) % len(chars)]) | |
| row.append("\033[0m") # Reset at end | |
| colored.append(''.join(row)) | |
| scenarios.append(("Smart colored", '\n'.join(colored))) | |
| # 4. Worst case - every character has unique color | |
| worst = [] | |
| for y in range(height): | |
| row = [] | |
| for x in range(width): | |
| # Every char gets a color code | |
| row.append(f"\033[38;2;{x%256};{y%256};{(x+y)%256}m") | |
| row.append(chars[(x+y) % len(chars)]) | |
| row.append("\033[0m") | |
| worst.append(''.join(row)) | |
| scenarios.append(("Worst case (every char colored)", '\n'.join(worst))) | |
| print("=== Realistic Bandwidth Analysis @ 60 FPS ===\n") | |
| print(f"Frame: {width}x{height} chars @ {fps} fps") | |
| print(f"Total characters per frame: {width*height:,}\n") | |
| for name, frame in scenarios: | |
| frame_bytes = frame.encode('utf-8') | |
| compressed = zlib.compress(frame_bytes, level=6) | |
| bandwidth_bps = len(compressed) * fps * 8 | |
| bandwidth_kbps = bandwidth_bps / 1000 | |
| bandwidth_mbps = bandwidth_bps / 1_000_000 | |
| print(f"{name}:") | |
| print(f" Uncompressed: {len(frame_bytes):,} bytes/frame") | |
| print(f" Compressed: {len(compressed):,} bytes/frame ({len(compressed)/len(frame_bytes):.1%})") | |
| print(f" Bandwidth: {bandwidth_kbps:.1f} kbps ({bandwidth_mbps:.3f} Mbps)") | |
| print() | |
| print("=== Video Comparison ===") | |
| print("1080p60 H.264 typical bitrates:") | |
| print(" Low quality: 6.0 Mbps") | |
| print(" Medium quality: 10.0 Mbps") | |
| print(" High quality: 15.0 Mbps") | |
| print(" Twitch 1080p60: 6.0 Mbps") | |
| print(" YouTube 1080p60: 12.0 Mbps") | |
| print("\n=== Bandwidth Savings vs 10 Mbps 1080p60 video ===") | |
| for name, frame in scenarios: | |
| compressed = zlib.compress(frame.encode('utf-8'), level=6) | |
| bandwidth_mbps = (len(compressed) * fps * 8) / 1_000_000 | |
| savings = (1 - bandwidth_mbps/10.0) * 100 | |
| ratio = 10.0 / bandwidth_mbps if bandwidth_mbps > 0 else float('inf') | |
| print(f"{name:30s}: {savings:+6.1f}% {'(saves)' if savings > 0 else '(uses more)'} | Video is {ratio:.1f}x larger") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
=== Realistic Bandwidth Analysis @ 60 FPS ===
Frame: 203x64 chars @ 60 fps
Total characters per frame: 12,992
Simple/static:
Uncompressed: 13,056 bytes/frame
Compressed: 104 bytes/frame (0.8%)
Bandwidth: 49.9 kbps (0.050 Mbps)
Typical ASCII art:
Uncompressed: 13,055 bytes/frame
Compressed: 340 bytes/frame (2.6%)
Bandwidth: 163.2 kbps (0.163 Mbps)
Smart colored:
Uncompressed: 26,687 bytes/frame
Compressed: 3,283 bytes/frame (12.3%)
Bandwidth: 1575.8 kbps (1.576 Mbps)
Worst case (every char colored):
Uncompressed: 233,548 bytes/frame
Compressed: 44,019 bytes/frame (18.8%)
Bandwidth: 21129.1 kbps (21.129 Mbps)
=== Video Comparison ===
1080p60 H.264 typical bitrates:
Low quality: 6.0 Mbps
Medium quality: 10.0 Mbps
High quality: 15.0 Mbps
Twitch 1080p60: 6.0 Mbps
YouTube 1080p60: 12.0 Mbps
=== Bandwidth Savings vs 10 Mbps 1080p60 video ===
Simple/static : +99.5% (saves) | Video is 200.3x larger
Typical ASCII art : +98.4% (saves) | Video is 61.3x larger
Smart colored : +84.2% (saves) | Video is 6.3x larger
Worst case (every char colored): -111.3% (uses more) | Video is 0.5x larger