Last active
August 29, 2015 14:16
-
-
Save morten-olsen/53d78ed394aa695b1c80 to your computer and use it in GitHub Desktop.
Calculations of an compression algorithm which can (should, very slightly) compress random data
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
console.clear(); | |
var targetReduction = 22, // Decompressor in KB | |
patternBytes = 1, | |
sequenceLengths = [4,5], | |
blocksize = 4; // Block size of FS in KB | |
// ---- Lot of technical mumbo-jumbo | |
var logs = [], | |
totalCompression = 0, | |
totalBytes = 0, | |
i; | |
logs.push('Original target: ' + targetReduction + ' KB'); | |
if (targetReduction % blocksize != 0) targetReduction += blocksize - (targetReduction % blocksize); | |
logs.push('Actual target: ' + targetReduction + ' KB'); | |
logs.push('Patterns: ' + patternBytes * 256); | |
targetReduction = targetReduction * 1024; | |
filesize = 1000 * 1024 * 1024; // Uses 1 GB as base for calculation | |
for (i = sequenceLengths.length - 1; i >= 0; i--) { | |
var bytes = 1 / Math.pow(256, sequenceLengths[i]) * Math.pow(256, patternBytes) * filesize, | |
reduction = (bytes * sequenceLengths[i]), | |
body = filesize - reduction, | |
header = (bytes * (patternBytes + Math.ceil(bytes / 256))), | |
compression = reduction - header; | |
totalBytes += bytes; | |
totalCompression += compression; | |
filesize -= reduction * 2; | |
logs.push('Sequence: ' + sequenceLengths[i] + ': ' + (compression / 1024).toFixed(5) + ' KB') | |
}; | |
logs.push('Total reduction pr gb: ' + (totalCompression / 1024).toFixed(5) + ' KB'); | |
logs.push('Size needed: ' + (targetReduction / totalCompression).toFixed(5) + ' GB'); | |
if (!!console && !!console.log) console.log(logs.join('\r\n')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment