/xmlbench/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/xmlbench/trunk
4 by Suren A. Chilingaryan
Mono validation and transformation benchmarks
1
using System;
2
using System.IO;
3
using System.Xml;
4
5
namespace XMLBench {
6
 abstract public class XMLBench {
7
    public string schema_file;
8
    public string schema_location;
9
    
10
    public void Bench(string[] args) {
11
	if (args.Length<2) {
12
	    Console.WriteLine("Usage:\n\tme <iterations> <xml file|xmlgen|opcgen|xmark> [size|schema] [schema_location]");
13
	}
14
15
	int iterations = Convert.ToInt32(args[0]);
16
	
17
	bool mode;
18
	if ((args[1] == "xmlgen")||(args[1] == "opcgen")||(args[1] == "xmark")) {
19
	    switch (args[1]) {
20
	     case "xmlgen":
21
	        schema_file = "../xml.files/generated.xsd";
22
	        schema_location = "../xml.files/generated.xsd";
23
	     break;
24
	     case "opcgen":
25
	        schema_file = "../xml.files/opc.xsd";
26
		schema_location = "http://opcfoundation.org/webservices/XMLDA/1.0/";
27
	     break;
28
	     default:
29
	        schema_file = args[2];
8 by Suren A. Chilingaryan
QT pull parser and fixes
30
		schema_location = (args.Length>3)?args[3]:args[2];
4 by Suren A. Chilingaryan
Mono validation and transformation benchmarks
31
	     break;
32
	    }
33
	    mode = true;
34
	} else {
35
	    mode = false;
36
	    schema_file = args[2];
8 by Suren A. Chilingaryan
QT pull parser and fixes
37
	    schema_location = (args.Length>3)?args[3]:args[2];
4 by Suren A. Chilingaryan
Mono validation and transformation benchmarks
38
	}
39
	
40
	DateTime pre, post;
41
	TimeSpan ts = new TimeSpan(0);
42
	Disp d = new Disp();
43
	
44
	InitXML();
45
	
46
	FileStream xml;
47
	
48
	if (mode) xml = new FileStream("../xml.tmp/0.xml", FileMode.Open);
49
	else xml = new FileStream(args[1], FileMode.Open);
50
	
51
	ParseXML(xml, iterations, 0);
52
	
53
	xml.Close();
54
	
55
	for (int i = 0; i < iterations; i++) {
5 by Suren A. Chilingaryan
DOM Creation benchmark for mono and tango
56
	    if (mode) xml = new FileStream("../xml.tmp/" + (i+1) + ".xml", FileMode.Open);
4 by Suren A. Chilingaryan
Mono validation and transformation benchmarks
57
	    else xml = new FileStream(args[1], FileMode.Open);
58
	    
59
    	    pre = DateTime.Now;
60
	    ParseXML(xml, iterations, 0);
61
	    post = DateTime.Now;
62
	    d.disp_event((post - pre).TotalMilliseconds);
63
	    
64
	    xml.Close();
65
	    
66
	    ts += post - pre;
67
68
	}
69
	d.disp_post();
70
71
	TimeSpan vts = new TimeSpan(0);
72
	Disp dv = new Disp();
73
74
	InitXML_Validation(schema_file, schema_location);
75
76
	if (mode) xml = new FileStream("../xml.tmp/0.xml", FileMode.Open);
77
	else xml = new FileStream(args[1], FileMode.Open);
78
	
79
	ValidateXML(xml, iterations, 0);
80
	
81
	xml.Close();
82
	
83
	for (int i = 0; i < iterations; i++) {
5 by Suren A. Chilingaryan
DOM Creation benchmark for mono and tango
84
	    if (mode) xml = new FileStream("../xml.tmp/" + (i+1) + ".xml", FileMode.Open);
4 by Suren A. Chilingaryan
Mono validation and transformation benchmarks
85
	    else xml = new FileStream(args[1], FileMode.Open);
86
	    
87
    	    pre = DateTime.Now;
88
	    ValidateXML(xml, iterations, 0);
89
	    post = DateTime.Now;
90
	    dv.disp_event((post - pre).TotalMilliseconds);
91
//	    Console.WriteLine((post - pre).TotalMilliseconds);
92
	    
93
	    xml.Close();
94
	    
95
	    vts += post - pre;
96
97
	}
98
	dv.disp_post();
99
	
100
	ReleaseXML();
101
	
102
	ts = vts - ts;
103
104
	if (args[1] == "opcgen") {
105
	    Console.WriteLine("Mono Validation Time: " + ts.TotalMilliseconds + " ms");
106
	} else {
107
//	    Console.WriteLine("Mono Time: " + ts.TotalMilliseconds/iterations + " ms");
108
//	    Console.WriteLine("Mono Time: " + (dv.disp_m-d.disp_m) + "(" + (300*(d.disp_d+dv.disp_d)/(dv.disp_m-d.disp_m)) + "%)");
109
	    Console.WriteLine("Mono Validation Time: " + (ts.TotalMilliseconds/iterations) + "(" + (300*(d.disp_d+dv.disp_d)/(dv.disp_m-d.disp_m)) + "%)");
110
	}
111
    }
112
    virtual public void InitXML() {}
113
    virtual public void InitXML_Validation(string schema_file, string schema_location) {}
114
    virtual public void ReleaseXML() {}
115
    abstract public void ParseXML(Stream xml, int iters, int iter);
116
    abstract public void ValidateXML(Stream xml, int iters, int iter);
117
 }
118
}