/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
#include <stdio.h>
#include <sys/time.h>
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/framework/MemBufInputSource.hpp>
#include <xercesc/parsers/XercesDOMParser.hpp>

#include "tools.h"

#if defined(XERCES_HAS_CPP_NAMESPACE)
    XERCES_CPP_NAMESPACE_USE
#endif


#ifdef FAST_MEMORY
#define FASTMM_BUF_SIZE 134217728
class FASTMemoryManager : public MemoryManager {
 protected:
    void *buf;
    int cursize;
    int pos;
 public:
    FASTMemoryManager() {
	cursize = FASTMM_BUF_SIZE;
	pos = 0;
	buf = malloc(FASTMM_BUF_SIZE);
	if (!buf) exit(-1);
    }
    
    void * allocate (XMLSize_t size) {
	void *res;

	int mod = size%16;
	if (mod) bsize += 16-mod;

	if (pos + size > cursize) {
	    while (pos + size > cursize) cursize *= 2;
	    buf = realloc(buf, cursize);
	    if (!buf) exit(-1);
	}
	
	res = (char*)buf+pos;
	pos += size;
	return res;
    }
    
    void deallocate (void *p) {
    }
    
    void clean() {
	pos = 0;
    }
    
    ~FASTMemoryManager() {
	free(buf);
    }
} fastmm;
#endif /* FAST_MEMORY */



void initXML(struct TestData *td) {
    XMLPlatformUtils::Initialize();
#ifdef FAST_MEMORY
#endif /* FAST_MEMORY */
}

void releaseXML(struct TestData *td) {
#ifdef FAST_MEMORY
#endif /* FAST_MEMORY */
    XMLPlatformUtils::Terminate();
}

void parseXML(struct TestData *td, unsigned long iter) {
    const char id[5]="ID1\0";
    MemBufInputSource *buffer;
    XercesDOMParser *parser;

#ifdef FAST_MEMORY
    fastmm.clean();
    parser = new XercesDOMParser(NULL,&fastmm);
#else
    parser = new XercesDOMParser;
#endif /* FAST_MEMORY */

    buffer=new MemBufInputSource((XMLByte*)td->xml,td->xmllen,(const char*)&id);
    buffer->setCopyBufToStream(false);
    parser->parse(*buffer);
    delete buffer;
    delete parser;
}


int main(int argc, char *argv[]) {
    return Test(argc,argv);
}