public static void testSpeed(String name)
     {
        // Test speed
        System.out.println("\n\nSpeed test for " + name);
        int[] repeats = { 3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3 };
        final int size = 500000;
        final int iter = 100;
        Random random = new Random();

        for (int jj=0; jj<3; jj++)
        {
            System.out.println("\nTest "+(jj+1));
            byte[] values1 = new byte[size];
            byte[] values2 = new byte[size];
            long delta1 = 0, delta2 = 0;

            for (int ii=0; ii<iter; ii++)
            {
                int idx = 0;

                for (int i=0; i<size; i++)
                {
                    int i0 = i;
                    int len = repeats[idx];
                    idx = (idx + 1) & 0x0F;
                    byte b = (byte) random.nextInt(256);

                    if (i0+len >= size)
                        len = size-i0-1;

                    for (int j=i0; j<i0+len; j++)
                    {
                       values1[j] = b;
                       i++;
                    }
                }

                // Encode
                ByteArrayOutputStream os = new ByteArrayOutputStream(size*2);
                OutputBitStream obs = new DefaultOutputBitStream(os, size);
                EntropyEncoder ec = getEncoder(name, obs);
                long before1 = System.nanoTime();
                
                if (ec.encode(values1, 0, values1.length) < 0)
                {
                   System.out.println("Encoding error");
                   System.exit(1);
                }

                ec.dispose();
                long after1 = System.nanoTime();
                delta1 += (after1 - before1);
                obs.close();

                // Decode
                byte[] buf = os.toByteArray();
                InputBitStream ibs = new DefaultInputBitStream(new ByteArrayInputStream(buf), size);
                EntropyDecoder ed = getDecoder(name, ibs);
                long before2 = System.nanoTime();
                
                if (ed.decode(values2, 0, size) < 0)
                {
                   System.out.println("Decoding error");
                   System.exit(1);
                }

                ed.dispose();
                long after2 = System.nanoTime();
                delta2 += (after2 - before2);
                ibs.close();

                // Sanity check
                for (int i=0; i<size; i++)
                {
                   if (values1[i] != values2[i])
                   {
                      System.out.println("Error at index "+i+" ("+values1[i]
                              +"<->"+values2[i]+")");
                      break;
                   }
                }
            }

            final long prod = (long) iter * (long) size;
            System.out.println("Encode [ms]       : " + delta1/1000000L);
            System.out.println("Throughput [KB/s] : " + prod * 1000000L / delta1 * 1000L / 1024L);
            System.out.println("Decode [ms]       : " + delta2/1000000L);
            System.out.println("Throughput [KB/s] : " + prod * 1000000L / delta2 * 1000L / 1024L);
        }
    }