Browse Source

Worked on getting caching in the engine. Worked on the CLI a little bit

master
Drew Short 11 years ago
parent
commit
2d46d862f0
  1. 5
      src/main/java/com/sothr/imagetools/AppCLI.java
  2. 19
      src/main/java/com/sothr/imagetools/AppConfig.java
  3. 18
      src/main/scala/com/sothr/imagetools/Engine.scala
  4. 17
      src/main/scala/com/sothr/imagetools/image/ImageCache.scala
  5. 16
      src/main/scala/com/sothr/imagetools/util/Timing.scala
  6. 266
      src/test/scala/com/sothr/imagetools/hash/HashServiceTest.scala

5
src/main/java/com/sothr/imagetools/AppCLI.java

@ -1,6 +1,5 @@
package com.sothr.imagetools; package com.sothr.imagetools;
import com.sothr.imagetools.image.ImageCache;
import com.sothr.imagetools.image.SimilarImages; import com.sothr.imagetools.image.SimilarImages;
import org.apache.commons.cli.BasicParser; import org.apache.commons.cli.BasicParser;
import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLine;
@ -11,8 +10,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import scala.collection.immutable.List; import scala.collection.immutable.List;
import java.text.ParseException;
/** /**
* CLI interface for Image Tools * CLI interface for Image Tools
*/ */
@ -42,7 +39,7 @@ class AppCLI {
private static void process(CommandLine cmd) { private static void process(CommandLine cmd) {
//scan a comma separated list of paths to search for image similarities //scan a comma separated list of paths to search for image similarities
Engine engine = new Engine(new ImageCache());
Engine engine = new Engine();
if (cmd.hasOption('s')) { if (cmd.hasOption('s')) {
String scanList = cmd.getOptionValue('s'); String scanList = cmd.getOptionValue('s');
String[] paths = scanList.split(","); String[] paths = scanList.split(",");

19
src/main/java/com/sothr/imagetools/AppConfig.java

@ -41,14 +41,6 @@ public class AppConfig {
configCache(); configCache();
} }
public static void configCache() {
if (!configuredCache) {
cacheManager = CacheManager.newInstance();
configuredCache = true;
logger.info("Configured EHCache");
}
}
public static void configLogging(String location) { public static void configLogging(String location) {
//Logging Config //Logging Config
//remove previous configuration if it exists //remove previous configuration if it exists
@ -109,6 +101,7 @@ public class AppConfig {
if (!configuredLogging) { if (!configuredLogging) {
configLogging(LOGSETTINGSFILE); configLogging(LOGSETTINGSFILE);
configuredLogging = true; configuredLogging = true;
logger.info("Configured logging");
} }
} }
@ -121,11 +114,21 @@ public class AppConfig {
PropertiesService.loadProperties(DEFAULTPROPERTIESFILE, null); PropertiesService.loadProperties(DEFAULTPROPERTIESFILE, null);
} }
loadedProperties = true; loadedProperties = true;
logger.info("Loaded properties");
}
}
public static void configCache() {
if (!configuredCache) {
cacheManager = CacheManager.newInstance();
configuredCache = true;
logger.info("Configured EHCache");
} }
} }
public static void saveProperties() { public static void saveProperties() {
PropertiesService.saveXMLProperties(USERPROPERTIESFILE); PropertiesService.saveXMLProperties(USERPROPERTIESFILE);
logger.debug("Saved properties");
} }
} }

18
src/main/scala/com/sothr/imagetools/Engine.scala

@ -1,17 +1,18 @@
package com.sothr.imagetools package com.sothr.imagetools
import com.sothr.imagetools.image.{ImageCache, SimilarImages, ImageFilter, Image}
import scala.collection.immutable
import com.sothr.imagetools.image.{SimilarImages, ImageFilter, Image}
import scala.collection.mutable import scala.collection.mutable
import java.io.File import java.io.File
import grizzled.slf4j.Logging import grizzled.slf4j.Logging
import net.sf.ehcache.Element
/** /**
* Created by drew on 1/26/14. * Created by drew on 1/26/14.
*/ */
class Engine(var imageCache:ImageCache = new ImageCache()) extends Logging{
class Engine() extends Logging{
val imageFilter:ImageFilter = new ImageFilter() val imageFilter:ImageFilter = new ImageFilter()
val imageCache = AppConfig.cacheManager.getCache("images")
def getImagesForDirectory(directoryPath:String):List[Image] = { def getImagesForDirectory(directoryPath:String):List[Image] = {
debug(s"Looking for images in directory: $directoryPath") debug(s"Looking for images in directory: $directoryPath")
@ -21,10 +22,12 @@ class Engine(var imageCache:ImageCache = new ImageCache()) extends Logging{
val files = directory.listFiles(imageFilter) val files = directory.listFiles(imageFilter)
debug(s"Found ${files.length} files that are images in directory: $directoryPath") debug(s"Found ${files.length} files that are images in directory: $directoryPath")
for (file <- files) { for (file <- files) {
if (imageCache.contains(file.getAbsolutePath)) {
images += imageCache.get(file.getAbsolutePath)
if (imageCache.isKeyInCache(file.getAbsolutePath)) {
images += imageCache.get(file.getAbsolutePath).asInstanceOf[Image]
} else { } else {
images += ImageService.getImage(file)
val image = ImageService.getImage(file)
imageCache.put(new Element(file.getAbsolutePath, image))
images += image
} }
} }
} else { } else {
@ -40,6 +43,7 @@ class Engine(var imageCache:ImageCache = new ImageCache()) extends Logging{
val ignoreSet = new mutable.HashSet[Image]() val ignoreSet = new mutable.HashSet[Image]()
val allSimilarImages = new mutable.MutableList[SimilarImages]() val allSimilarImages = new mutable.MutableList[SimilarImages]()
var processedCount = 0 var processedCount = 0
var similarCount = 0
for (rootImage <- images) { for (rootImage <- images) {
if (!ignoreSet.contains(rootImage)) { if (!ignoreSet.contains(rootImage)) {
info(s"Processed ${processedCount}/${images.length - ignoreSet.size} About ${images.length - processedCount} images to go") info(s"Processed ${processedCount}/${images.length - ignoreSet.size} About ${images.length - processedCount} images to go")
@ -52,6 +56,7 @@ class Engine(var imageCache:ImageCache = new ImageCache()) extends Logging{
debug(s"Image: ${image.imagePath} is similar") debug(s"Image: ${image.imagePath} is similar")
similarImages += image similarImages += image
ignoreSet += image ignoreSet += image
similarCount += 1
} }
} }
} }
@ -63,6 +68,7 @@ class Engine(var imageCache:ImageCache = new ImageCache()) extends Logging{
processedCount += 1 processedCount += 1
} }
} }
info(s"Finished processing ${images.size} images. Found $similarCount similar images")
allSimilarImages.toList allSimilarImages.toList
} }
} }

17
src/main/scala/com/sothr/imagetools/image/ImageCache.scala

@ -1,17 +0,0 @@
package com.sothr.imagetools.image
import scala.collection.mutable
/**
* Created by drew on 1/26/14.
*/
class ImageCache {
private val cache = new mutable.HashMap[String, Image]()
def contains(imagePath:String) = cache.contains(imagePath)
def get(imagePath:String) = cache(imagePath)
def add(imagePath:String, image:Image) = cache.put(imagePath,image)
def size:Int = cache.size
}

16
src/main/scala/com/sothr/imagetools/util/Timing.scala

@ -17,15 +17,19 @@ trait Timing extends Logging{
val result = block // call-by-name val result = block // call-by-name
val t1 = System.currentTimeMillis val t1 = System.currentTimeMillis
info("Elapsed time: " + (t1 - t0) + "ms") info("Elapsed time: " + (t1 - t0) + "ms")
(t1 - t0)
t1 - t0
} }
def getMean(times:Long*):Long = { def getMean(times:Long*):Long = {
var ag = 0L
for (i <- times.indices) {
ag += times(i)
}
(ag / times.length)
getMean(times.toArray[Long])
}
def getMean(times:Array[Long]):Long = {
var ag = 0L
for (i <- times.indices) {
ag += times(i)
}
ag / times.length
} }
} }

266
src/test/scala/com/sothr/imagetools/hash/HashServiceTest.scala

@ -5,12 +5,16 @@ import javax.imageio.ImageIO
import java.io.File import java.io.File
import com.sothr.imagetools.dto.ImageHashDTO import com.sothr.imagetools.dto.ImageHashDTO
import net.sf.ehcache.{Cache, Element} import net.sf.ehcache.{Cache, Element}
import scala.collection.mutable
/** /**
* Created by dev on 1/23/14. * Created by dev on 1/23/14.
*/ */
class HashServiceTest extends BaseTest { class HashServiceTest extends BaseTest {
// Define the number of runs the benchmarking tests should use
val benchmarkRuns = 10
def dhashTestCase(filePath:String):Long = { def dhashTestCase(filePath:String):Long = {
val sample = new File(filePath) val sample = new File(filePath)
val image = ImageIO.read(sample) val image = ImageIO.read(sample)
@ -18,32 +22,30 @@ class HashServiceTest extends BaseTest {
} }
test("Benchmark DHash") { test("Benchmark DHash") {
info("Benchmarking DHash")
info("DHash Large Image 3684x2736")
val largeTime1 = getTime { dhashTestCase(TestParams.LargeSampleImage1) }
val largeTime2 = getTime { dhashTestCase(TestParams.LargeSampleImage1) }
val largeTime3 = getTime { dhashTestCase(TestParams.LargeSampleImage1) }
val largeTime4 = getTime { dhashTestCase(TestParams.LargeSampleImage1) }
val largeTime5 = getTime { dhashTestCase(TestParams.LargeSampleImage1) }
val largeMean = getMean(largeTime1, largeTime2, largeTime3, largeTime4, largeTime5)
info(s"The mean time of 5 tests for large was: $largeMean ms")
info("DHash Medium Image 1824x1368")
val mediumTime1 = getTime { dhashTestCase(TestParams.MediumSampleImage1) }
val mediumTime2 = getTime { dhashTestCase(TestParams.MediumSampleImage1) }
val mediumTime3 = getTime { dhashTestCase(TestParams.MediumSampleImage1) }
val mediumTime4 = getTime { dhashTestCase(TestParams.MediumSampleImage1) }
val mediumTime5 = getTime { dhashTestCase(TestParams.MediumSampleImage1) }
val mediumMean = getMean(mediumTime1, mediumTime2, mediumTime3, mediumTime4, mediumTime5)
info(s"The mean time of 5 tests for medium was: $mediumMean ms")
info("DHash Small Image 912x684")
val smallTime1 = getTime { dhashTestCase(TestParams.SmallSampleImage1) }
val smallTime2 = getTime { dhashTestCase(TestParams.SmallSampleImage1) }
val smallTime3 = getTime { dhashTestCase(TestParams.SmallSampleImage1) }
val smallTime4 = getTime { dhashTestCase(TestParams.SmallSampleImage1) }
val smallTime5 = getTime { dhashTestCase(TestParams.SmallSampleImage1) }
val smallMean = getMean(smallTime1, smallTime2, smallTime3, smallTime4, smallTime5)
info(s"The mean time of 5 tests for small was: $smallMean ms")
assert(true)
info("Benchmarking DHash")
info("DHash Large Image 3684x2736")
val time = new mutable.MutableList[Long]()
for (runNum <- 0 until benchmarkRuns) {
time += getTime { dhashTestCase(TestParams.LargeSampleImage1) }
}
val largeMean = getMean(time.toArray[Long])
info(s"The mean time of ${time.size} tests for large was: $largeMean ms")
time.clear()
info("DHash Medium Image 1824x1368")
for (runNum <- 0 until benchmarkRuns) {
time += getTime { dhashTestCase(TestParams.MediumSampleImage1) }
}
val mediumMean = getMean(time.toArray[Long])
info(s"The mean time of ${time.size} tests for medium was: $mediumMean ms")
time.clear()
info("DHash Small Image 912x684")
for (runNum <- 0 until benchmarkRuns) {
time += getTime { dhashTestCase(TestParams.SmallSampleImage1) }
}
val smallMean = getMean(time.toArray[Long])
info(s"The mean time of ${time.size} tests for small was: $smallMean ms")
time.clear()
assert(true)
} }
test("Confirm Largest DHash Output ") { test("Confirm Largest DHash Output ") {
@ -112,29 +114,27 @@ class HashServiceTest extends BaseTest {
test("Benchmark AHash") { test("Benchmark AHash") {
info("Benchmarking AHash") info("Benchmarking AHash")
info("AHash Large Image 3684x2736") info("AHash Large Image 3684x2736")
val largeTime1 = getTime { ahashTestCase(TestParams.LargeSampleImage1) }
val largeTime2 = getTime { ahashTestCase(TestParams.LargeSampleImage1) }
val largeTime3 = getTime { ahashTestCase(TestParams.LargeSampleImage1) }
val largeTime4 = getTime { ahashTestCase(TestParams.LargeSampleImage1) }
val largeTime5 = getTime { ahashTestCase(TestParams.LargeSampleImage1) }
val largeMean = getMean(largeTime1, largeTime2, largeTime3, largeTime4, largeTime5)
info(s"The mean time of 5 tests for large was: $largeMean ms")
val time = new mutable.MutableList[Long]()
for (runNum <- 0 until benchmarkRuns) {
time += getTime { ahashTestCase(TestParams.LargeSampleImage1) }
}
val largeMean = getMean(time.toArray[Long])
info(s"The mean time of ${time.size} tests for large was: $largeMean ms")
time.clear()
info("AHash Medium Image 1824x1368") info("AHash Medium Image 1824x1368")
val mediumTime1 = getTime { ahashTestCase(TestParams.MediumSampleImage1) }
val mediumTime2 = getTime { ahashTestCase(TestParams.MediumSampleImage1) }
val mediumTime3 = getTime { ahashTestCase(TestParams.MediumSampleImage1) }
val mediumTime4 = getTime { ahashTestCase(TestParams.MediumSampleImage1) }
val mediumTime5 = getTime { ahashTestCase(TestParams.MediumSampleImage1) }
val mediumMean = getMean(mediumTime1, mediumTime2, mediumTime3, mediumTime4, mediumTime5)
info(s"The mean time of 5 tests for medium was: $mediumMean ms")
for (runNum <- 0 until benchmarkRuns) {
time += getTime { ahashTestCase(TestParams.MediumSampleImage1) }
}
val mediumMean = getMean(time.toArray[Long])
info(s"The mean time of ${time.size} tests for medium was: $mediumMean ms")
time.clear()
info("AHash Small Image 912x684") info("AHash Small Image 912x684")
val smallTime1 = getTime { ahashTestCase(TestParams.SmallSampleImage1) }
val smallTime2 = getTime { ahashTestCase(TestParams.SmallSampleImage1) }
val smallTime3 = getTime { ahashTestCase(TestParams.SmallSampleImage1) }
val smallTime4 = getTime { ahashTestCase(TestParams.SmallSampleImage1) }
val smallTime5 = getTime { ahashTestCase(TestParams.SmallSampleImage1) }
val smallMean = getMean(smallTime1, smallTime2, smallTime3, smallTime4, smallTime5)
info(s"The mean time of 5 tests for small was: $smallMean ms")
for (runNum <- 0 until benchmarkRuns) {
time += getTime { ahashTestCase(TestParams.SmallSampleImage1) }
}
val smallMean = getMean(time.toArray[Long])
info(s"The mean time of ${time.size} tests for small was: $smallMean ms")
time.clear()
assert(true) assert(true)
} }
@ -189,29 +189,27 @@ class HashServiceTest extends BaseTest {
test("Benchmark PHash") { test("Benchmark PHash") {
info("Benchmarking PHash") info("Benchmarking PHash")
info("PHash Large Image 3684x2736") info("PHash Large Image 3684x2736")
val largeTime1 = getTime { phashTestCase(TestParams.LargeSampleImage1) }
val largeTime2 = getTime { phashTestCase(TestParams.LargeSampleImage1) }
val largeTime3 = getTime { phashTestCase(TestParams.LargeSampleImage1) }
val largeTime4 = getTime { phashTestCase(TestParams.LargeSampleImage1) }
val largeTime5 = getTime { phashTestCase(TestParams.LargeSampleImage1) }
val largeMean = getMean(largeTime1, largeTime2, largeTime3, largeTime4, largeTime5)
info(s"The mean time of 5 tests for large was: $largeMean ms")
val time = new mutable.MutableList[Long]()
for (runNum <- 0 until benchmarkRuns) {
time += getTime { phashTestCase(TestParams.LargeSampleImage1) }
}
val largeMean = getMean(time.toArray[Long])
info(s"The mean time of ${time.size} tests for large was: $largeMean ms")
time.clear()
info("PHash Medium Image 1824x1368") info("PHash Medium Image 1824x1368")
val mediumTime1 = getTime { phashTestCase(TestParams.MediumSampleImage1) }
val mediumTime2 = getTime { phashTestCase(TestParams.MediumSampleImage1) }
val mediumTime3 = getTime { phashTestCase(TestParams.MediumSampleImage1) }
val mediumTime4 = getTime { phashTestCase(TestParams.MediumSampleImage1) }
val mediumTime5 = getTime { phashTestCase(TestParams.MediumSampleImage1) }
val mediumMean = getMean(mediumTime1, mediumTime2, mediumTime3, mediumTime4, mediumTime5)
info(s"The mean time of 5 tests for medium was: $mediumMean ms")
for (runNum <- 0 until benchmarkRuns) {
time += getTime { phashTestCase(TestParams.MediumSampleImage1) }
}
val mediumMean = getMean(time.toArray[Long])
info(s"The mean time of ${time.size} tests for medium was: $mediumMean ms")
time.clear()
info("PHash Small Image 912x684") info("PHash Small Image 912x684")
val smallTime1 = getTime { phashTestCase(TestParams.SmallSampleImage1) }
val smallTime2 = getTime { phashTestCase(TestParams.SmallSampleImage1) }
val smallTime3 = getTime { phashTestCase(TestParams.SmallSampleImage1) }
val smallTime4 = getTime { phashTestCase(TestParams.SmallSampleImage1) }
val smallTime5 = getTime { phashTestCase(TestParams.SmallSampleImage1) }
val smallMean = getMean(smallTime1, smallTime2, smallTime3, smallTime4, smallTime5)
info(s"The mean time of 5 tests for small was: $smallMean ms")
for (runNum <- 0 until benchmarkRuns) {
time += getTime { phashTestCase(TestParams.SmallSampleImage1) }
}
val smallMean = getMean(time.toArray[Long])
info(s"The mean time of ${time.size} tests for small was: $smallMean ms")
time.clear()
assert(true) assert(true)
} }
@ -263,30 +261,28 @@ class HashServiceTest extends BaseTest {
test("Benchmark MD5") { test("Benchmark MD5") {
info("Benchmarking MD5") info("Benchmarking MD5")
info("PHash Large Image 3684x2736")
val largeTime1 = getTime { md5TestCase(TestParams.LargeSampleImage1) }
val largeTime2 = getTime { md5TestCase(TestParams.LargeSampleImage1) }
val largeTime3 = getTime { md5TestCase(TestParams.LargeSampleImage1) }
val largeTime4 = getTime { md5TestCase(TestParams.LargeSampleImage1) }
val largeTime5 = getTime { md5TestCase(TestParams.LargeSampleImage1) }
val largeMean = getMean(largeTime1, largeTime2, largeTime3, largeTime4, largeTime5)
info(s"The mean time of 5 tests for large was: $largeMean ms")
info("PHash Medium Image 1824x1368")
val mediumTime1 = getTime { md5TestCase(TestParams.MediumSampleImage1) }
val mediumTime2 = getTime { md5TestCase(TestParams.MediumSampleImage1) }
val mediumTime3 = getTime { md5TestCase(TestParams.MediumSampleImage1) }
val mediumTime4 = getTime { md5TestCase(TestParams.MediumSampleImage1) }
val mediumTime5 = getTime { md5TestCase(TestParams.MediumSampleImage1) }
val mediumMean = getMean(mediumTime1, mediumTime2, mediumTime3, mediumTime4, mediumTime5)
info(s"The mean time of 5 tests for medium was: $mediumMean ms")
info("PHash Small Image 912x684")
val smallTime1 = getTime { md5TestCase(TestParams.SmallSampleImage1) }
val smallTime2 = getTime { md5TestCase(TestParams.SmallSampleImage1) }
val smallTime3 = getTime { md5TestCase(TestParams.SmallSampleImage1) }
val smallTime4 = getTime { md5TestCase(TestParams.SmallSampleImage1) }
val smallTime5 = getTime { md5TestCase(TestParams.SmallSampleImage1) }
val smallMean = getMean(smallTime1, smallTime2, smallTime3, smallTime4, smallTime5)
info(s"The mean time of 5 tests for small was: $smallMean ms")
info("MD5 Large Image 3684x2736")
val time = new mutable.MutableList[Long]()
for (runNum <- 0 until benchmarkRuns) {
time += getTime { md5TestCase(TestParams.LargeSampleImage1) }
}
val largeMean = getMean(time.toArray[Long])
info(s"The mean time of ${time.size} tests for large was: $largeMean ms")
time.clear()
info("MD5 Medium Image 1824x1368")
for (runNum <- 0 until benchmarkRuns) {
time += getTime { md5TestCase(TestParams.MediumSampleImage1) }
}
val mediumMean = getMean(time.toArray[Long])
info(s"The mean time of ${time.size} tests for medium was: $mediumMean ms")
time.clear()
info("MD5 Small Image 912x684")
for (runNum <- 0 until benchmarkRuns) {
time += getTime { md5TestCase(TestParams.SmallSampleImage1) }
}
val smallMean = getMean(time.toArray[Long])
info(s"The mean time of ${time.size} tests for small was: $smallMean ms")
time.clear()
assert(true) assert(true)
} }
@ -329,59 +325,55 @@ class HashServiceTest extends BaseTest {
test("Benchmark getImageHashes with cache") { test("Benchmark getImageHashes with cache") {
info("Benchmarking getImageHashes with cache") info("Benchmarking getImageHashes with cache")
info("getImageHashes Large Image 3684x2736")
val largeTime1 = getTime { imageHashTestWithCacheCase(TestParams.LargeSampleImage1) }
val largeTime2 = getTime { imageHashTestWithCacheCase(TestParams.LargeSampleImage1) }
val largeTime3 = getTime { imageHashTestWithCacheCase(TestParams.LargeSampleImage1) }
val largeTime4 = getTime { imageHashTestWithCacheCase(TestParams.LargeSampleImage1) }
val largeTime5 = getTime { imageHashTestWithCacheCase(TestParams.LargeSampleImage1) }
val largeMean = getMean(largeTime1, largeTime2, largeTime3, largeTime4, largeTime5)
info(s"The mean time of 5 tests for large was: $largeMean ms")
info("getImageHashes Medium Image 1824x1368")
val mediumTime1 = getTime { imageHashTestWithCacheCase(TestParams.MediumSampleImage1) }
val mediumTime2 = getTime { imageHashTestWithCacheCase(TestParams.MediumSampleImage1) }
val mediumTime3 = getTime { imageHashTestWithCacheCase(TestParams.MediumSampleImage1) }
val mediumTime4 = getTime { imageHashTestWithCacheCase(TestParams.MediumSampleImage1) }
val mediumTime5 = getTime { imageHashTestWithCacheCase(TestParams.MediumSampleImage1) }
val mediumMean = getMean(mediumTime1, mediumTime2, mediumTime3, mediumTime4, mediumTime5)
info(s"The mean time of 5 tests for medium was: $mediumMean ms")
info("getImageHashes Small Image 912x684")
val smallTime1 = getTime { imageHashTestWithCacheCase(TestParams.SmallSampleImage1) }
val smallTime2 = getTime { imageHashTestWithCacheCase(TestParams.SmallSampleImage1) }
val smallTime3 = getTime { imageHashTestWithCacheCase(TestParams.SmallSampleImage1) }
val smallTime4 = getTime { imageHashTestWithCacheCase(TestParams.SmallSampleImage1) }
val smallTime5 = getTime { imageHashTestWithCacheCase(TestParams.SmallSampleImage1) }
val smallMean = getMean(smallTime1, smallTime2, smallTime3, smallTime4, smallTime5)
info(s"The mean time of 5 tests for small was: $smallMean ms")
info("getImageHashes with cache Large Image 3684x2736")
val time = new mutable.MutableList[Long]()
for (runNum <- 0 until benchmarkRuns) {
time += getTime { imageHashTestWithCacheCase(TestParams.LargeSampleImage1) }
}
val largeMean = getMean(time.toArray[Long])
info(s"The mean time of ${time.size} tests for large was: $largeMean ms")
time.clear()
info("getImageHashes with cache Medium Image 1824x1368")
for (runNum <- 0 until benchmarkRuns) {
time += getTime { imageHashTestWithCacheCase(TestParams.MediumSampleImage1) }
}
val mediumMean = getMean(time.toArray[Long])
info(s"The mean time of ${time.size} tests for medium was: $mediumMean ms")
time.clear()
info("getImageHashes with cache Small Image 912x684")
for (runNum <- 0 until benchmarkRuns) {
time += getTime { imageHashTestWithCacheCase(TestParams.SmallSampleImage1) }
}
val smallMean = getMean(time.toArray[Long])
info(s"The mean time of ${time.size} tests for small was: $smallMean ms")
time.clear()
assert(true) assert(true)
} }
test("Benchmark getImageHashes") { test("Benchmark getImageHashes") {
info("Benchmarking getImageHashes") info("Benchmarking getImageHashes")
info("getImageHashes Large Image 3684x2736") info("getImageHashes Large Image 3684x2736")
val largeTime1 = getTime { imageHashTestCase(TestParams.LargeSampleImage1) }
val largeTime2 = getTime { imageHashTestCase(TestParams.LargeSampleImage1) }
val largeTime3 = getTime { imageHashTestCase(TestParams.LargeSampleImage1) }
val largeTime4 = getTime { imageHashTestCase(TestParams.LargeSampleImage1) }
val largeTime5 = getTime { imageHashTestCase(TestParams.LargeSampleImage1) }
val largeMean = getMean(largeTime1, largeTime2, largeTime3, largeTime4, largeTime5)
info(s"The mean time of 5 tests for large was: $largeMean ms")
val time = new mutable.MutableList[Long]()
for (runNum <- 0 until benchmarkRuns) {
time += getTime { imageHashTestCase(TestParams.LargeSampleImage1) }
}
val largeMean = getMean(time.toArray[Long])
info(s"The mean time of ${time.size} tests for large was: $largeMean ms")
time.clear()
info("getImageHashes Medium Image 1824x1368") info("getImageHashes Medium Image 1824x1368")
val mediumTime1 = getTime { imageHashTestCase(TestParams.MediumSampleImage1) }
val mediumTime2 = getTime { imageHashTestCase(TestParams.MediumSampleImage1) }
val mediumTime3 = getTime { imageHashTestCase(TestParams.MediumSampleImage1) }
val mediumTime4 = getTime { imageHashTestCase(TestParams.MediumSampleImage1) }
val mediumTime5 = getTime { imageHashTestCase(TestParams.MediumSampleImage1) }
val mediumMean = getMean(mediumTime1, mediumTime2, mediumTime3, mediumTime4, mediumTime5)
info(s"The mean time of 5 tests for medium was: $mediumMean ms")
for (runNum <- 0 until benchmarkRuns) {
time += getTime { imageHashTestCase(TestParams.MediumSampleImage1) }
}
val mediumMean = getMean(time.toArray[Long])
info(s"The mean time of ${time.size} tests for medium was: $mediumMean ms")
time.clear()
info("getImageHashes Small Image 912x684") info("getImageHashes Small Image 912x684")
val smallTime1 = getTime { imageHashTestCase(TestParams.SmallSampleImage1) }
val smallTime2 = getTime { imageHashTestCase(TestParams.SmallSampleImage1) }
val smallTime3 = getTime { imageHashTestCase(TestParams.SmallSampleImage1) }
val smallTime4 = getTime { imageHashTestCase(TestParams.SmallSampleImage1) }
val smallTime5 = getTime { imageHashTestCase(TestParams.SmallSampleImage1) }
val smallMean = getMean(smallTime1, smallTime2, smallTime3, smallTime4, smallTime5)
info(s"The mean time of 5 tests for small was: $smallMean ms")
for (runNum <- 0 until benchmarkRuns) {
time += getTime { imageHashTestCase(TestParams.SmallSampleImage1) }
}
val smallMean = getMean(time.toArray[Long])
info(s"The mean time of ${time.size} tests for small was: $smallMean ms")
time.clear()
assert(true) assert(true)
} }

Loading…
Cancel
Save