/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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
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")) {
	    switch (args[1]) {
	     case "xmlgen":
	        schema_file = "../xml.files/generated.xsd";
	        schema_location = "../xml.files/generated.xsd";
	     break;
	     case "opcgen":
	        schema_file = "../xml.files/opc.xsd";
		schema_location = "http://opcfoundation.org/webservices/XMLDA/1.0/";
	     break;
	     default:
	        schema_file = args[2];
		schema_location = (args.Length>3)?args[3]:args[2];
	     break;
	    }
	    mode = true;
	} else {
	    mode = false;
	    schema_file = args[2];
	    schema_location = (args.Length>3)?args[3]:args[2];
	}
	
	DateTime pre, post;
	TimeSpan ts = new TimeSpan(0);
	Disp d = new Disp();
	
	InitXML();
	
	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);
	
	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);
	    
    	    pre = DateTime.Now;
	    ParseXML(xml, iterations, 0);
	    post = DateTime.Now;
	    d.disp_event((post - pre).TotalMilliseconds);
	    
	    xml.Close();
	    
	    ts += post - pre;

	}
	d.disp_post();

	TimeSpan vts = new TimeSpan(0);
	Disp dv = new Disp();

	InitXML_Validation(schema_file, schema_location);

	if (mode) xml = new FileStream("../xml.tmp/0.xml", FileMode.Open);
	else xml = new FileStream(args[1], FileMode.Open);
	
	ValidateXML(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);
	    
    	    pre = DateTime.Now;
	    ValidateXML(xml, iterations, 0);
	    post = DateTime.Now;
	    dv.disp_event((post - pre).TotalMilliseconds);
//	    Console.WriteLine((post - pre).TotalMilliseconds);
	    
	    xml.Close();
	    
	    vts += post - pre;

	}
	dv.disp_post();
	
	ReleaseXML();
	
	ts = vts - ts;

	if (args[1] == "opcgen") {
	    Console.WriteLine("Mono Validation Time: " + ts.TotalMilliseconds + " ms");
	} else {
//	    Console.WriteLine("Mono Time: " + ts.TotalMilliseconds/iterations + " ms");
//	    Console.WriteLine("Mono Time: " + (dv.disp_m-d.disp_m) + "(" + (300*(d.disp_d+dv.disp_d)/(dv.disp_m-d.disp_m)) + "%)");
	    Console.WriteLine("Mono Validation Time: " + (ts.TotalMilliseconds/iterations) + "(" + (300*(d.disp_d+dv.disp_d)/(dv.disp_m-d.disp_m)) + "%)");
	}
    }
    virtual public void InitXML() {}
    virtual public void InitXML_Validation(string schema_file, string schema_location) {}
    virtual public void ReleaseXML() {}
    abstract public void ParseXML(Stream xml, int iters, int iter);
    abstract public void ValidateXML(Stream xml, int iters, int iter);
 }
}