Click here to Skip to main content
15,894,460 members
Articles / Programming Languages / XML

VTD-XML: XML Processing for the Future (Part I)

Rate me:
Please Sign up or sign in to vote.
4.50/5 (17 votes)
17 Apr 2008CPOL10 min read 96.3K   1.1K   59  
Introduce VTD-XML, the future of XML processing
/* 
 * Copyright (C) 2002-2004 XimpleWare, info@ximpleware.com
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#include "stdafx.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>

struct exception_context the_exception_context[1];

/* this is a simple benchmark file */
/* after make, type benchmark_gcc  */
/* <filename> to benchmark its performance */

int main(int argc, char *argv[])
{ 
	int j=0,k=0,j1=0;
	//int t;
	clock_t c1,c2;
	//printf("size of clock_t: %d \n",sizeof(clock_t));
	exception e;
	//UByte a = -1;
	//int i = a;
	//struct _stat fs;
	FILE *f = NULL;
	UByte *xml = NULL;
	VTDGen *vg = NULL;
	VTDNav *vn = NULL;
	struct stat s;
		
	f = fopen(argv[1],"rb");
	stat(argv[1],&s);
	//i=(int)_filelength(f->_file);
	printf("size of the file is %d \n",(int)s.st_size);
	xml = (UByte *)malloc(sizeof(UByte)*(int)s.st_size); 
	k=(int)fread(xml,sizeof(UByte),s.st_size,f);
	j1 = (int) (800000000/k);
	printf("j1 : %d \n",j1);
	printf(" read in %d bytes \n",k);
	c1 = clock();
	vg = createVTDGen();
	
	Try{
		for (j=0;j<j1;j++){
		setDoc_BR2(vg,xml,s.st_size,0,k);
		parse(vg,TRUE);
		//vn = getNav(vg);
		//freeVTDGen(vg);
		//freeVTDNav(vn);
		}
	}
	Catch (e){
		if (e.et == parse_exception)
		printf("exception e ==> %s \n %s\n", e.msg,e.sub_msg);
	}
	
	c2 = clock();
	printf("mili-sec elapsed : %d \n",(int)(((int)c2-(int)c1)/CLOCKS_PER_SEC*1000));
	printf("average latency : %f ms \n",(double)(c2-c1)/CLOCKS_PER_SEC*1000/j1);
	printf("performance : %f MB/sec \n", 
		((double)k*j*CLOCKS_PER_SEC/((double)(1<<20)*(c2-c1)))
	);
	return 1;	
	
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Chief Technology Officer XimpleWare
United States United States
Jimmy Zhang is a cofounder of XimpleWare, a provider of high performance XML processing solutions. He has working experience in the fields of electronic design automation and Voice over IP for a number of Silicon Valley high-tech companies. He holds both a BS and MS from the department of EECS from U.C. Berkeley.

Comments and Discussions