Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
Created a generic ViewImage performance render test.
luce093fb228dfd
diff --git a/test/ViewImageJPGPerfTest.java b/test/ViewImageJPGPerfTest.javadeleted file mode 100755index 5ac5b3f00..000000000--- a/test/ViewImageJPGPerfTest.java+++ /dev/null@@ -1,83 +0,0 @@-import java.io.FileNotFoundException;-import java.io.IOException;-import java.io.InputStream;--import net.yacy.peers.graphics.EncodedImage;-import net.yacy.server.serverObjects;--// ViewImageJPGPerfTest.java-// ------------------------// part of YaCy-// (C) by Michael Peter Christen; [email protected]-// first published on http://www.anomic.de-// Frankfurt, Germany, 2006-// created 03.04.2006-//-// This program is free software; you can redistribute it and/or modify-// it under the terms of the GNU General Public License as published by-// the Free Software Foundation; either version 2 of the License, or-// (at your option) any later version.-//-// This program is distributed in the hope that it will be useful,-// but WITHOUT ANY WARRANTY; without even the implied warranty of-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-// GNU General Public License for more details.-//-// You should have received a copy of the GNU General Public License-// along with this program; if not, write to the Free Software-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA--/**- * Test to measure JPG render performance by ViewImage- *- * @author luc- *- */-public class ViewImageJPGPerfTest {-- private static final String TEST_IMG_RESOURCE = "/viewImageTest/test/JPEG_example_JPG_RIP_100.jpg";-- private static byte[] getTestImageBytes() throws IOException {- InputStream inStream = ViewImageJPGPerfTest.class.getResourceAsStream(TEST_IMG_RESOURCE);- if (inStream == null) {- throw new FileNotFoundException(TEST_IMG_RESOURCE);- }- byte[] res = new byte[inStream.available()];- try {- inStream.read(res);- } finally {- inStream.close();- }- return res;- }- // TODO pour info dernier test : 11167ms-- /**- * Test image (JPEG_example_JPG_RIP_100.jpg) is scaled, and cropped.- *- * @throws IOException- */- public static void main(String args[]) throws IOException {- byte[] resourceb = getTestImageBytes();- serverObjects post = new serverObjects();- /* Scale test image to 1/10 */- post.put("maxwidth", "31");- post.put("maxheight", "23");- /* Make it square */- post.put("quadratic", "");-- String urlString = ViewImageJPGPerfTest.class.getResource(TEST_IMG_RESOURCE).getFile();-- long beginTime = System.nanoTime();- for (int step = 0; step < 500; step++) {- EncodedImage img = ViewImage.parseAndScale(post, true, urlString, "jpg", false, resourceb);- if (img == null) {- throw new IOException("Image render failed");- }- }- long endTime = System.nanoTime();- System.out.println("Render time(ms) : " + (endTime - beginTime) / 1000000);-- }--}diff --git a/test/ViewImagePerfTest.java b/test/ViewImagePerfTest.javanew file mode 100755index 000000000..d7a6502b4--- /dev/null+++ b/test/ViewImagePerfTest.java@@ -0,0 +1,171 @@+import java.io.File;+import java.io.FileInputStream;+import java.io.IOException;+import java.io.InputStream;+import java.net.URL;++import net.yacy.cora.util.ConcurrentLog;+import net.yacy.peers.graphics.EncodedImage;+import net.yacy.server.serverObjects;++// ViewImagePerfTest.java+// -----------------------+// part of YaCy+// (C) by Michael Peter Christen; [email protected]+// first published on http://www.anomic.de+// Frankfurt, Germany, 2006+// created 03.04.2006+//+// This program is free software; you can redistribute it and/or modify+// it under the terms of the GNU General Public License as published by+// the Free Software Foundation; either version 2 of the License, or+// (at your option) any later version.+//+// This program is distributed in the hope that it will be useful,+// but WITHOUT ANY WARRANTY; without even the implied warranty of+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+// GNU General Public License for more details.+//+// You should have received a copy of the GNU General Public License+// along with this program; if not, write to the Free Software+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA++/**+ * Test to measure image render performance by ViewImage+ *+ * @author luc+ *+ */+public class ViewImagePerfTest {++ /** Default image */+ private static final String DEFAULT_IMG_RESOURCE = "/viewImageTest/test/JPEG_example_JPG_RIP_100.jpg";++ /** Default render max width (JPEG_example_JPG_RIP_100.jpg width / 10) */+ private static final int DEFAULT_MAX_WIDTH = 31;++ /** Default render max height (JPEG_example_JPG_RIP_100.jpg height / 10) */+ private static final int DEFAULT_MAX_HEIGHT = 23;++ /** Default encoding format */+ private static final String DEFAUL_EXT = "png";++ /**+ * @param testFile+ * file to load+ * @return testFile content as a bytes array+ * @throws IOException+ * when an error occured while loading+ */+ private static byte[] getBytes(File testFile) throws IOException {+ InputStream inStream = new FileInputStream(testFile);+ byte[] res = new byte[inStream.available()];+ try {+ inStream.read(res);+ } finally {+ inStream.close();+ }+ return res;+ }++ /**+ * @param args+ * first item may contain file URL+ * @return file to be used : specified as first in args or default one+ */+ private static File getTestFile(String args[]) {+ String fileURL;+ if (args != null && args.length > 0) {+ fileURL = args[0];+ } else {+ URL defaultURL = ViewImagePerfTest.class.getResource(DEFAULT_IMG_RESOURCE);+ if (defaultURL == null) {+ throw new IllegalArgumentException("File not found : " + DEFAULT_IMG_RESOURCE);+ }+ fileURL = defaultURL.getFile();+ }+ return new File(fileURL);+ }++ /**+ * Build post parameters to used with ViewImage+ *+ * @param args+ * main parameters : second and third items may respectively+ * contain max width and max height+ * @return a serverObjects instance+ */+ private static serverObjects makePostParams(String args[]) {+ serverObjects post = new serverObjects();+ int maxWidth = DEFAULT_MAX_WIDTH;+ if (args != null && args.length > 1) {+ maxWidth = Integer.parseInt(args[1]);+ }+ post.put("maxwidth", String.valueOf(maxWidth));++ int maxHeight = DEFAULT_MAX_HEIGHT;+ if (args != null && args.length > 2) {+ maxHeight = Integer.parseInt(args[2]);+ }+ post.put("maxheight", String.valueOf(maxHeight));+ /* Make it square by default */+ post.put("quadratic", "");+ return post;+ }++ /**+ *+ * @param args+ * main parameters : fourth item may contain extension+ * @return extension to use for encoding+ */+ private static String getEncodingExt(String args[]) {+ String ext = DEFAUL_EXT;+ if (args != null && args.length > 3) {+ ext = args[3];+ }+ return ext;+ }++ /**+ * Test image (JPEG_example_JPG_RIP_100.jpg) is scaled, and cropped.+ *+ * @throws IOException+ */+ public static void main(String args[]) throws IOException {+ File imgFile = getTestFile(args);+ byte[] resourceb = getBytes(imgFile);+ String ext = getEncodingExt(args);+ serverObjects post = makePostParams(args);++ String urlString = imgFile.getAbsolutePath();++ System.out.println("Measuring ViewImage render with file : " + urlString + " encoded To : " + ext);+ try {+ /* Max test total time (s) */+ int maxTotalTime = 20;+ long beginTime, time, minTime = Long.MAX_VALUE, maxTime = 0, meanTime = 0, totalTime = 0;+ int step = 0;+ for (step = 0; (totalTime / 1000000000) < maxTotalTime; step++) {+ beginTime = System.nanoTime();+ EncodedImage img = ViewImage.parseAndScale(post, true, urlString, ext, false, resourceb);+ time = System.nanoTime() - beginTime;+ minTime = Math.min(minTime, time);+ maxTime = Math.max(maxTime, time);+ totalTime += time;+ if (img == null) {+ throw new IOException("Image render failed");+ }+ }+ meanTime = totalTime / step;+ System.out.println("Render total time (ms) : " + (totalTime) / 1000000 + " on " + step + " steps.");+ System.out.println("Render mean time (ms) : " + (meanTime) / 1000000);+ System.out.println("Render min time (ms) : " + (minTime) / 1000000);+ System.out.println("Render max time (ms) : " + (maxTime) / 1000000);+ } finally {+ ConcurrentLog.shutdown();+ }++ }++}