001: /*
002: * Copyright (C) 2008 XStream Committers.
003: * All rights reserved.
004: *
005: * The software in this package is published under the terms of the BSD
006: * style license a copy of which has been included with this distribution in
007: * the LICENSE.txt file.
008: *
009: * Created on 01. January 2008 by Joerg Schaible
010: */
011: package com.thoughtworks.xstream.benchmark.cache;
012:
013: import com.thoughtworks.xstream.benchmark.cache.products.Cache122;
014: import com.thoughtworks.xstream.benchmark.cache.products.AliasedAttributeCache;
015: import com.thoughtworks.xstream.benchmark.cache.products.DefaultImplementationCache;
016: import com.thoughtworks.xstream.benchmark.cache.products.NoCache;
017: import com.thoughtworks.xstream.benchmark.cache.products.RealClassCache;
018: import com.thoughtworks.xstream.benchmark.cache.products.SerializedClassCache;
019: import com.thoughtworks.xstream.benchmark.cache.targets.BasicTarget;
020: import com.thoughtworks.xstream.benchmark.cache.targets.ExtendedTarget;
021: import com.thoughtworks.xstream.benchmark.cache.targets.ReflectionTarget;
022: import com.thoughtworks.xstream.benchmark.cache.targets.SerializableTarget;
023: import com.thoughtworks.xstream.tools.benchmark.Harness;
024: import com.thoughtworks.xstream.tools.benchmark.Product;
025: import com.thoughtworks.xstream.tools.benchmark.metrics.DeserializationSpeedMetric;
026: import com.thoughtworks.xstream.tools.benchmark.metrics.SerializationSpeedMetric;
027: import com.thoughtworks.xstream.tools.benchmark.reporters.TextReporter;
028:
029: import org.apache.commons.cli.CommandLine;
030: import org.apache.commons.cli.Options;
031: import org.apache.commons.cli.ParseException;
032: import org.apache.commons.cli.Parser;
033: import org.apache.commons.cli.PosixParser;
034:
035: import java.io.PrintWriter;
036:
037: /**
038: * Main application to run harness for Profile benchmark.
039: *
040: * @author Jörg Schaible
041: */
042: public class CacheBenchmark {
043: public static void main(String[] args) {
044: int counter = 10000;
045: Product product = null;
046:
047: Options options = new Options();
048: options.addOption("p", "product", true,
049: "Class name of the product to use for benchmark");
050: options.addOption("n", true, "Number of repetitions");
051:
052: Parser parser = new PosixParser();
053: try {
054: CommandLine commandLine = parser.parse(options, args);
055: if (commandLine.hasOption('p')) {
056: product = (Product) Class.forName(
057: commandLine.getOptionValue('p')).newInstance();
058: }
059: if (commandLine.hasOption('n')) {
060: counter = Integer.parseInt(commandLine
061: .getOptionValue('n'));
062: }
063: } catch (ParseException e) {
064: e.printStackTrace();
065: } catch (InstantiationException e) {
066: e.printStackTrace();
067: } catch (IllegalAccessException e) {
068: e.printStackTrace();
069: } catch (ClassNotFoundException e) {
070: e.printStackTrace();
071: }
072:
073: Harness harness = new Harness();
074: // harness.addMetric(new SerializationSpeedMetric(1) {
075: // public String toString() {
076: // return "Initial run serialization";
077: // }
078: // });
079: // harness.addMetric(new DeserializationSpeedMetric(1, false) {
080: // public String toString() {
081: // return "Initial run deserialization";
082: // }
083: // });
084: harness.addMetric(new SerializationSpeedMetric(counter));
085: harness
086: .addMetric(new DeserializationSpeedMetric(counter,
087: false));
088: if (product == null) {
089: harness.addProduct(new NoCache());
090: harness.addProduct(new Cache122());
091: harness.addProduct(new RealClassCache());
092: harness.addProduct(new SerializedClassCache());
093: harness.addProduct(new AliasedAttributeCache());
094: harness.addProduct(new DefaultImplementationCache());
095: harness.addProduct(new NoCache());
096: } else {
097: harness.addProduct(product);
098: }
099: harness.addTarget(new BasicTarget());
100: harness.addTarget(new ExtendedTarget());
101: harness.addTarget(new ReflectionTarget());
102: harness.addTarget(new SerializableTarget());
103: harness
104: .run(new TextReporter(new PrintWriter(System.out, true)));
105: System.out.println("Done.");
106: }
107: }
|