01: /*
02: * Copyright (C) 2006 Joe Walnes.
03: * Copyright (C) 2006, 2007, 2008 XStream Committers.
04: * All rights reserved.
05: *
06: * The software in this package is published under the terms of the BSD
07: * style license a copy of which has been included with this distribution in
08: * the LICENSE.txt file.
09: *
10: * Created on 15. July 2006 by Joe Walnes
11: */
12: package com.thoughtworks.xstream.tools.benchmark.metrics;
13:
14: import com.thoughtworks.xstream.tools.benchmark.Metric;
15: import com.thoughtworks.xstream.tools.benchmark.Product;
16: import com.thoughtworks.xstream.tools.benchmark.Target;
17:
18: import java.io.ByteArrayOutputStream;
19:
20: /**
21: * Determines the size of the serialized form of an object (in bytes).
22: *
23: * @author Joe Walnes
24: * @see com.thoughtworks.xstream.tools.benchmark.Harness
25: * @see Metric
26: */
27: public class SizeMetric implements Metric {
28:
29: public double run(Product product, Target target) throws Exception {
30: return run(product, target.target());
31: }
32:
33: /**
34: *@deprecated since 1.3
35: */
36: public double run(Product product, Object object) throws Exception {
37: ByteArrayOutputStream buffer = new ByteArrayOutputStream();
38: product.serialize(object, buffer);
39: return buffer.size();
40: }
41:
42: public String toString() {
43: return "Size of serialized data";
44: }
45:
46: public String unit() {
47: return "bytes";
48: }
49:
50: public boolean biggerIsBetter() {
51: return false;
52: }
53: }
|