/xmlbench/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/xmlbench/trunk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using System;
using System.IO;
using System.Xml;

namespace XMLBench {
 abstract public class XMLBench {
    public string schema_file;
    public string schema_location;
    
    public void Bench(string[] args) {
	if (args.Length<2) {
	    Console.WriteLine("Usage:\n\tme <iterations> <xml file|xmlgen|opcgen|xmark> [size|schema] [schema_location]");
	}

	int iterations = Convert.ToInt32(args[0]);
	
	bool mode;
	if ((args[1] == "xmlgen")||(args[1] == "opcgen")||(args[1] == "xmark")) {
	    mode = true;
	} else {
	    mode = false;
	}
	
	DateTime pre, post;
	TimeSpan te = new TimeSpan(0);
	TimeSpan ts = new TimeSpan(0);
	Disp de = new Disp();
	Disp ds = new Disp();
	
	InitXML();
	InitXML_Security();
	
	FileStream xml;
	
	if (mode) xml = new FileStream("../xml.tmp/0.xml", FileMode.Open);
	else xml = new FileStream(args[1], FileMode.Open);
	
	ParseXML(xml, iterations, 0);
	EncryptXML(xml, iterations, 0);
	DecryptXML(xml, iterations, 0);
	SignXML(xml, iterations, 0);
	VerifyXML(xml, iterations, 0);
	
	xml.Close();
	
	for (int i = 0; i < iterations; i++) {
	    if (mode) xml = new FileStream("../xml.tmp/" + (i+1) + ".xml", FileMode.Open);
	    else xml = new FileStream(args[1], FileMode.Open);
	    
	    ParseXML(xml, iterations, 0);

    	    pre = DateTime.Now;
	    EncryptXML(xml, iterations, 0);
	    DecryptXML(xml, iterations, 0);
	    post = DateTime.Now;
	    de.disp_event((post - pre).TotalMilliseconds);
	    te += post - pre;

    	    pre = DateTime.Now;
	    SignXML(xml, iterations, 0);
	    VerifyXML(xml, iterations, 0);
	    post = DateTime.Now;
	    ds.disp_event((post - pre).TotalMilliseconds);
	    ts += post - pre;
	    
	    xml.Close();
	    

	}
	de.disp_post();
	ds.disp_post();
	
	ReleaseXML();
	
	if (args[1] == "opcgen") {
	    Console.WriteLine("Mono Encryption Time: " + te.TotalMilliseconds + " ms");
	    Console.WriteLine("Mono Signature Time: " + ts.TotalMilliseconds + " ms");
	} else {
	    Console.WriteLine("Mono Encryption Time: " + (te.TotalMilliseconds/iterations) + "(" + (300*(de.disp_d)/(de.disp_m)) + "%)");
	    Console.WriteLine("Mono Signature Time: " + (ts.TotalMilliseconds/iterations) + "(" + (300*(ds.disp_d)/(ds.disp_m)) + "%)");
	}
    }
    virtual public void InitXML() {}
    virtual public void InitXML_Security() {}
    virtual public void ReleaseXML() {}
    abstract public void ParseXML(Stream xml, int iters, int iter);
    abstract public void SignXML(Stream xml, int iters, int iter);
    abstract public void VerifyXML(Stream xml, int iters, int iter);
    abstract public void EncryptXML(Stream xml, int iters, int iter);
    abstract public void DecryptXML(Stream xml, int iters, int iter);
 }
}