Basic compression speed?

Hi, i was wondering how fast a text compression program should go, i have my code all ready, but it geas extremely slow compared to professional ones and I wanted to know about how fast a basic text compression program should go, thank you for your help.
[261 byte] By [mythicwolf88a] at [2007-10-1 0:51:05]
# 1

Try using DeflatorOutputStream, everything you write to it is compressed automatically. InflatorInputStream does the reverse.

Write to

import java.io.ByteArrayOutputStream;

import java.io.File;

import java.io.FileInputStream;

import java.io.IOException;

import java.util.zip.DeflaterOutputStream;

public class CompressTest {

public static void main(String args[]) throws IOException {

String str = readFile(args[0]);

compressText(str);

}

public static String readFile(String fileName) throws IOException {

File file = new File(fileName);

byte[] bytes = new byte[(int) file.length()];

FileInputStream fis = new FileInputStream(file);

fis.read(bytes);

fis.close();

return new String(bytes, 0);

}

public static void compressText(String text) {

try {

byte[] stringBytes = text.getBytes();

long start = System.currentTimeMillis();

ByteArrayOutputStream baos = new ByteArrayOutputStream();

DeflaterOutputStream dos = new DeflaterOutputStream(baos);

dos.write(stringBytes);

dos.close();

byte[] bytes = baos.toByteArray();

long end = System.currentTimeMillis();

double compressionRatio = (double) text.length() / bytes.length;

double runTime = (end - start) / 1000.0;

System.out.println("Compression ratio=" + compressionRatio + ", compression time=" + runTime + " secs");

} catch (IOException e) {

e.printStackTrace();

}

}

}

I ran this for the king james version of the bible. A big text file from ftp://unboundftp.biola.edu/pub/kjv.zip and got the following results for the text file.

Compression ratio=3.2839847108115876, compression time=1.047 secs

That is about 1 second to compress a 5 MB of text (on a 1.8 GHz AMD)

Peter-Lawreya at 2007-7-8 1:06:39 > top of Java-index,Other Topics,Algorithms...
# 2
Thank you very much, i guess I have a long way to go before I get mine to work as good as it should...as long as mine is better than ricky's :)
mythicwolf88a at 2007-7-8 1:06:39 > top of Java-index,Other Topics,Algorithms...
# 3

My arithmetic compressor did around 30kB/s - 300kB/s IIRC

It was on computer underclocked to 1.8 GHz

I consider compressing 700MB avi under an hour as very nice for an arithmetic compressor, so... You have the answer.

Static "huffman" tree is faster, but not as much interesting.

Raghar

Lord_of_the_chaosa at 2007-7-8 1:06:39 > top of Java-index,Other Topics,Algorithms...
# 4
If you need the utlimate fast compression library to compare against, see "lzop"www.lzop.orgOn my 2.0 GHz, dscent harddrive computer:lzop: 10 MB/sWinZip: 4 MB/sGil
gilroittoa at 2007-7-8 1:06:39 > top of Java-index,Other Topics,Algorithms...
# 5
wow, my noobish powers only got me 2kb/s with huffman compression, i feel really dumb now, lol.
mythicwolf88a at 2007-7-8 1:06:39 > top of Java-index,Other Topics,Algorithms...