Example #1
0
        public static int[] uncompress(ByteIntegerCODEC codec, sbyte[] data, int len)
        {
            int[]      outBuf = new int[len + 1024];
            IntWrapper inPos  = new IntWrapper();
            IntWrapper outPos = new IntWrapper();

            codec.uncompress(data, inPos, data.Length, outBuf, outPos);
            return(Arrays.copyOf(outBuf, outPos.get()));
        }
Example #2
0
        public static sbyte[] compress(ByteIntegerCODEC codec, int[] data)
        {
            sbyte[]    outBuf = new sbyte[data.Length * 4 * 4];
            IntWrapper inPos  = new IntWrapper();
            IntWrapper outPos = new IntWrapper();

            codec.compress(data, inPos, data.Length, outBuf, outPos);
            return(Arrays.copyOf(outBuf, outPos.get()));
        }
Example #3
0
        /**
         * Standard benchmark byte byte-aligned schemes
         *
         * @param csvLog
         *                Writer for CSV log.
         * @param c
         *                the codec
         * @param data
         *                arrays of input data
         * @param repeat
         *                How many times to repeat the test
         * @param verbose
         *                whether to output result on screen
         */
        private static void testByteCodec(StreamWriter csvLog, int sparsity, ByteIntegerCODEC c, int[][] data, int repeat, bool verbose)
        {
            if (verbose)
            {
                Console.WriteLine("# " + c);
                Console.WriteLine("# bits per int, compress speed (mis), decompression speed (mis) ");
            }

            int N = data.Length;

            int totalSize = 0;
            int maxLength = 0;

            for (int k = 0; k < N; ++k)
            {
                totalSize += data[k].Length;
                if (data[k].Length > maxLength)
                {
                    maxLength = data[k].Length;
                }
            }

            sbyte[] compressBuffer   = new sbyte[8 * maxLength + 1024];
            int[]   decompressBuffer = new int[maxLength + 1024];

            // These variables hold time in microseconds (10^-6).
            long compressTime   = 0;
            long decompressTime = 0;

            int        size   = 0;
            IntWrapper inpos  = new IntWrapper();
            IntWrapper outpos = new IntWrapper();

            for (int r = 0; r < repeat; ++r)
            {
                size = 0;
                for (int k = 0; k < N; ++k)
                {
                    int[] backupdata = Arrays.copyOf(data[k],
                                                     data[k].Length);

                    // compress data.
                    long beforeCompress = Port.System.nanoTime() / 1000;
                    inpos.set(1);
                    outpos.set(0);
                    if (!(c is IntegratedByteIntegerCODEC))
                    {
                        Delta.delta(backupdata);
                    }
                    c.compress(backupdata, inpos, backupdata.Length
                               - inpos.get(), compressBuffer, outpos);
                    long afterCompress = Port.System.nanoTime() / 1000;

                    // measure time of compression.
                    compressTime += afterCompress - beforeCompress;

                    int thiscompsize = outpos.get() + 1;
                    size += thiscompsize;

                    // extract (uncompress) data
                    long beforeDecompress = Port.System.nanoTime() / 1000;
                    inpos.set(0);
                    outpos.set(1);
                    decompressBuffer[0] = backupdata[0];
                    c.uncompress(compressBuffer, inpos,
                                 thiscompsize - 1, decompressBuffer,
                                 outpos);
                    if (!(c is IntegratedByteIntegerCODEC))
                    {
                        Delta.fastinverseDelta(decompressBuffer);
                    }
                    long afterDecompress = Port.System.nanoTime() / 1000;

                    // measure time of extraction (uncompression).
                    decompressTime += afterDecompress
                                      - beforeDecompress;
                    if (outpos.get() != data[k].Length)
                    {
                        throw new Exception(
                                  "we have a bug (diff length) "
                                  + c + " expected "
                                  + data[k].Length
                                  + " got "
                                  + outpos.get());
                    }

                    // verify: compare original array with
                    // compressed and
                    // uncompressed.
                    for (int m = 0; m < outpos.get(); ++m)
                    {
                        if (decompressBuffer[m] != data[k][m])
                        {
                            throw new Exception(
                                      "we have a bug (actual difference), expected "
                                      + data[k][m]
                                      + " found "
                                      + decompressBuffer[m]
                                      + " at " + m);
                        }
                    }
                }
            }

            if (verbose)
            {
                double bitsPerInt      = size * 8.0 / totalSize;
                long   compressSpeed   = totalSize * repeat / (compressTime);
                long   decompressSpeed = totalSize * repeat / (decompressTime);

                Console.WriteLine("\t{0:0.00}\t{1}\t{2}", bitsPerInt, compressSpeed, decompressSpeed);
                csvLog.WriteLine("\"{0}\",{1},{2:0.00},{3},{4}", c, sparsity, bitsPerInt, compressSpeed, decompressSpeed);
            }
        }