All Downloads are FREE. Search and download functionalities are using the official Maven repository.

src.it.unimi.dsi.test.InputBitStreamSpeedTest Maven / Gradle / Ivy

Go to download

The DSI utilities are a mishmash of classes accumulated during the last twenty years in projects developed at the DSI (Dipartimento di Scienze dell'Informazione, i.e., Information Sciences Department), now DI (Dipartimento di Informatica, i.e., Informatics Department), of the Universita` degli Studi di Milano.

There is a newer version: 2.7.3
Show newest version
package it.unimi.dsi.test;

import it.unimi.dsi.io.InputBitStream;
import it.unimi.dsi.io.OutputBitStream;
import it.unimi.dsi.logging.ProgressLogger;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class InputBitStreamSpeedTest  {

	private InputBitStreamSpeedTest() {}

    public static void main(final String[] arg) throws IOException {
		int k;
		int n = Integer.parseInt(arg[0]);
		int i;
		java.util.Random r = new java.util.Random();
		ProgressLogger pl = new ProgressLogger();
		int data1[] = new int[1000000];
		int data2[] = new int[1000000];
		i = 1000000;
		while(i-- != 0) data2[i] = (data1[i] = r.nextInt(100)) + 1;


		k = 10;
		while(k-- != 0) {

			i = n;
			pl.start();
			OutputBitStream bos = new OutputBitStream(new FileOutputStream("test "), 16*1024);
			while(i-- != 0) bos.writeGamma(data1[i % 1000000]);
			bos.close();
			pl.done();

			System.err.println("Written " + n + " integers on OutputBitStream in " + pl.millis() + " ms (" + (1000.0 * n) / pl.millis() + " int/s)");


			pl.start();
			InputBitStream bis = new InputBitStream(new FileInputStream("test "), 16*1024);
			i = n;
			while(i-- != 0) bis.readGamma();
			bis.close();
			pl.stop();

			System.err.println("Read " + n + " integers from InputBitStream in " + pl.millis() + " ms (" + (1000.0 * n) / pl.millis() + " int/s)");

		}

/*		k = 10;
		while(k-- != 0) {

			i = n;
			pl.reset();
			pl.start();
			BitOutputStream bos = new BitOutputStream(new FileOutputStream("test "));
			while(i-- != 0) bos.writeGamma(data2[i % 1000000]);
			bos.close();
			pl.stop();

			System.err.println("Written " + n + " integers on BitOutputStream in " + pl.millis() + " ms (" + (1000.0 * n) / pl.millis() + " int/s)");


			pl.reset();
			pl.start();
			BitInputStream bis = new BitInputStream(new FileInputStream("test "));
			i = n;
			while(i-- != 0) bis.readGamma();
			bis.close();
			pl.stop();

			System.err.println("Read " + n + " integers from BitInputStream in " + pl.millis() + " ms (" + (1000.0 * n) / pl.millis() + " int/s)");

		}*/
    }


}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy