private static void benchTJSimpleAPI() { byte[] data = File.ReadAllBytes(inputFilePath); byte[] rawImg = null; byte[] recompressed = null; System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); using (TJDecompressor decomp = new TJDecompressor(data)) { using (TJCompressor comp = new TJCompressor()) { comp.setJPEGQuality(jpegQuality); for (int i = 0; i < numIterations; i++) { rawImg = decomp.decompress(); comp.setSourceImage(rawImg, decomp.getWidth(), decomp.getHeight()); recompressed = comp.compressToExactSize(); } } } sw.Stop(); PrintBenchmarkResult("turbojpegCLI simple API", sw.ElapsedMilliseconds); File.WriteAllBytes("out-libjpeg-turbo.jpg", recompressed); }