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

		final byte[] data = new byte[BUFFER_SIZE];

		final Random rnd = new Random(0xdeadbeef);
		rnd.nextBytes( data );

		final BitStream buffer = new BitStream( (KB_TO_WRITE+1)*1024 );

		long t = benchmark( () ->
		{
			for ( int i = 0 ; i < KB_TO_WRITE; i++ )
			{
				for ( final long b : data )
				{
					buffer.write( b & 0xffL , 8 );
				}
			}
		});

		float dataPerSecond = (KB_TO_WRITE/1024f) / (t/1000f);
		System.out.println("\nWrote "+KB_TO_WRITE+" in "+t+" ms ("+dataPerSecond+" MB/s)");

		/*
		 * Sanity check
		 */
		final byte[] bufferContents = buffer.getBytes(1024*8);
		if ( bufferContents.length != data.length ) {
			throw new RuntimeException("Length mismatch , expected: "+data.length+" , actual: "+bufferContents.length);
		}
		for ( int i = 0 ; i < bufferContents.length ; i++ )
		{
			final byte actual   = bufferContents[i];
			final byte expected = data[i];
			if ( expected != actual ) {
				throw new RuntimeException("Read error at offset "+i+" , expected 0b"+Long.toBinaryString( expected )+" , got 0b"+Long.toBinaryString( actual ) );
			}
		}

		t = benchmark( () ->
		{
			long sum = 0;
			for ( int j = 0 ; j < KB_TO_WRITE ; j++)
			{
				buffer.reset();
				for ( int i = 0 ; i < BUFFER_SIZE ; i++ )
				{
					sum += buffer.readLong( 8 );
				}
			}
			System.out.print("sum: "+sum);
		});
		dataPerSecond = (KB_TO_WRITE/1024f) / (t/1000f);
		System.out.println("\n\nRead "+KB_TO_WRITE+" in "+t+" ms ("+dataPerSecond+" MB/s)");
	}