DATASCOOTER
Support This Project
Custom Search

English Home
Russian Home
Quickstart
Performance
Guide
Download
Example
Contacts

Performance Comparison


Let's compare a performance of Datascooter-2.7 and Hibernate-3. The task for both - save,select, delete and save again into MySQl database 10000 objects of class ContextTestClassInt.
Class for testing Hibernate
package org.hibernateTest;

import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

import org.datascooter.utils.LangUtils;

@Entity
@Table(name = "context_test_int")
public class ContextTestClassInt implements Serializable {

	private static final long serialVersionUID = -4087169737119286586L;
	@Id
	@Column
	private Long id;
	@Column(name = "STRING_VALUE")
	String stringValue;
	@Column(name = "LONG_VALUE")
	Long longValue;
	@Column(name = "BIG_DECIMAL")
	BigDecimal bigDecimalValue;
	@Column(name = "TIME_VALUE")
	Date timestampValue;
	@Column(name = "BOOLEAN_VALUE")
	Boolean booleanValue;
	@Column(name = "INTEGER_VALUE")
	Integer integerValue;

	public ContextTestClassInt() {
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public ContextTestClassInt(Integer size, Long id) throws UnsupportedEncodingException {
		this.id = id;
		this.stringValue = LangUtils.repeat("1", size);
		this.longValue = new Long(size);
		this.bigDecimalValue = new BigDecimal(size);
		this.timestampValue = new Date();
		this.booleanValue = new Boolean(true);
		this.integerValue = size;
	}

	public String getStringValue() {
		return stringValue;
	}

	public void setStringValue(String stringValue) {
		this.stringValue = stringValue;
	}

	public Long getLongValue() {
		return longValue;
	}

	public void setLongValue(Long longValue) {
		this.longValue = longValue;
	}

	public BigDecimal getBigDecimalValue() {
		return bigDecimalValue;
	}

	public void setBigDecimalValue(BigDecimal bigDecimalValue) {
		this.bigDecimalValue = bigDecimalValue;
	}

	public Date getTimestampValue() {
		return timestampValue;
	}

	public void setTimestampValue(Date timestampValue) {
		this.timestampValue = timestampValue;
	}

	public Boolean getBooleanValue() {
		return booleanValue;
	}

	public void setBooleanValue(Boolean booleanValue) {
		this.booleanValue = booleanValue;
	}

	public Integer getIntegerValue() {
		return integerValue;
	}

	public void setIntegerValue(Integer integerValue) {
		this.integerValue = integerValue;
	}
}

	 

Class for testing Datascooter
	 
	 
package org.datascooter.mapping.core;

import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.datascooter.inface.IFlushable;
import org.datascooter.utils.LangUtils;

/**
 * This class is purposed for testing transfer the all types of data by
 * DataBaseContext STRING, LONG, BIGDECIMAL, TIMESTAMP, BOOLEAN, BLOB,CLOB, INT;
 * 
 * @author nemo
 * 
 */
public class ContextTestClassInt implements Serializable, IFlushable {

	private static final long serialVersionUID = 1481569024363272924L;
	private Long id;
	String stringValue;
	Long longValue;
	BigDecimal bigDecimalValue;
	Date timestampValue;
	Boolean booleanValue;
	Integer integerValue;

	public ContextTestClassInt() {
	}

	public ContextTestClassInt(Integer size, Long id) throws UnsupportedEncodingException {
		this.id = id;
		this.stringValue = LangUtils.repeat("1", size);
		this.longValue = new Long(size);
		this.bigDecimalValue = new BigDecimal(size);
		this.timestampValue = new Date();
		this.booleanValue = new Boolean(true);
		this.integerValue = size;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getStringValue() {
		return stringValue;
	}

	public void setStringValue(String stringValue) {
		this.stringValue = stringValue;
	}

	public Long getLongValue() {
		return longValue;
	}

	public void setLongValue(Long longValue) {
		this.longValue = longValue;
	}

	public BigDecimal getBigDecimalValue() {
		return bigDecimalValue;
	}

	public void setBigDecimalValue(BigDecimal bigDecimalValue) {
		this.bigDecimalValue = bigDecimalValue;
	}

	public Date getTimestampValue() {
		return timestampValue;
	}

	public void setTimestampValue(Date timestampValue) {
		this.timestampValue = timestampValue;
	}

	public Boolean getBooleanValue() {
		return booleanValue;
	}

	public void setBooleanValue(Boolean booleanValue) {
		this.booleanValue = booleanValue;
	}

	public Integer getIntegerValue() {
		return integerValue;
	}

	public void setIntegerValue(Integer integerValue) {
		this.integerValue = integerValue;
	}

	@Override
	public Object[] flush() {
		return new Object[] {
				id, stringValue, longValue, bigDecimalValue, timestampValue, booleanValue, integerValue
		};
	}

	@Override
	public void restore(Object[] fields) throws Exception {
		id = Long.valueOf(fields[0] + "");
		this.stringValue = fields[1] + "";
		this.longValue = new Long(fields[2] + "");
		this.bigDecimalValue = new BigDecimal(fields[3] + "");
		this.timestampValue = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(fields[4] + "");
		this.booleanValue = new Boolean(fields[5] + "");
		this.integerValue = new Integer(fields[6] + "");
		;
	}
}

	 

The test case for Hibernate
	 
	 
package org.hibernateTest;

import static org.junit.Assert.assertTrue;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.SessionFactory;
import org.hibernate.StatelessSession;
import org.hibernate.cfg.AnnotationConfiguration;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

public class HibernateTest {

	private static StatelessSession openSession;
	private static final int maxNum = 10000;
	private static List list = new ArrayList();
	private static long startMemoryUse;
	private static long endMemoryUse;
	private static List list2;

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		AnnotationConfiguration configuration = new AnnotationConfiguration().configure();
		final SessionFactory factory = configuration.buildSessionFactory();
		openSession = factory.openStatelessSession();
		for (int a = 0; a less maxNum; a++) {
			list.add(new ContextTestClassInt(1000, Long.valueOf(a + 1)));
		}
		System.out.println("Size of item:  " + TestUtils.sizeOf(list.get(0)));
		startMemoryUse = TestUtils.getMemoryUse();
		System.out.println("Start Memory use:  " + startMemoryUse);
		openSession.beginTransaction();
		openSession.createQuery("DELETE FROM " + ContextTestClassInt.class.getName());
		openSession.getTransaction().commit();
	}

	@Test
	public void a_save() throws Exception {
		openSession.beginTransaction();
		for (ContextTestClassInt contextTestClass : list) {
			openSession.insert(contextTestClass);
		}
		openSession.getTransaction().commit();
	}

	@SuppressWarnings("unchecked")
	@Test
	public void b_select() throws Exception {
		openSession.beginTransaction();
		list2 = openSession.createQuery("FROM " + ContextTestClassInt.class.getName()).list();
		openSession.getTransaction().commit();
		assertTrue("Size: " + list2.size() + "---" + list.size(), list2.size() == list.size());
	}

	@Test
	public void c_clear() throws Exception {
		openSession.beginTransaction();
		openSession.createQuery("DELETE FROM " + ContextTestClassInt.class.getName()).executeUpdate();
		openSession.getTransaction().commit();
	}

	@Test
	public void d_saveBatch() throws Exception {
		openSession.beginTransaction();
		for (Object contextTestClass : list2) {
			openSession.insert(contextTestClass);
		}
		openSession.getTransaction().commit();
	}

	@AfterClass
	public static void tearDown() throws Exception {
		endMemoryUse = TestUtils.getMemoryUse();
		System.out.println("Stop Memory use:  " + endMemoryUse);
		long memory = endMemoryUse - startMemoryUse;
		float approximateSize = memory / maxNum;
		System.out.println("Memory use :  " + memory);
		System.out.println("Hibernate eats on each object :  " + Math.round(approximateSize));
		openSession.beginTransaction();
		openSession.createQuery("DELETE FROM " + ContextTestClassInt.class.getName()).executeUpdate();
		openSession.getTransaction().commit();
	}
}

	
	

The test case for Datascooter
 
package org.datascooter.test;

import static org.junit.Assert.assertTrue;

import java.util.ArrayList;
import java.util.List;

import org.datascooter.DataScooter;
import org.datascooter.bundle.EntityMapper;
import org.datascooter.extension.EclipseExtensionReader;
import org.datascooter.impl.DataSnip;
import org.datascooter.impl.Snip;
import org.datascooter.inface.IDataManager;
import org.datascooter.mapping.core.ContextTestClassInt;
import org.datascooter.parser.DSBuilderProvider;
import org.datascooter.parser.DSConnectorProvider;
import org.datascooter.parser.DSDataSourceProvider;
import org.datascooter.parser.DSMappingProvider;
import org.datascooter.test.example.Address;
import org.datascooter.test.example.Location;
import org.datascooter.test.example.Owner;
import org.datascooter.test.example.Phone;
import org.datascooter.utils.SnipType;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

/**
 * This test made for checking productivity conditions and memory expence as
 * common as for each of processed objects. So - you can to compare with
 * Hibernate in stateless mode - it faster!!!
 * 
 * @author nemo
 * 
 */
public class StressTest {

	private static IDataManager DEFAULT;
	private static final int maxNum = 10000;
	private static List list = new ArrayList();
	private static Snip snip;
	private static long startMemoryUse;
	private static long endMemoryUse;

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		String userDir = System.getProperty("user.dir").replace(".test", "");
		DataScooter.start(
			true,
			userDir + "/datascooter.properties",
			new DSBuilderProvider(new EclipseExtensionReader("org.datascooter.clauseBuilder")),
			new DSConnectorProvider(new EclipseExtensionReader("org.datascooter.connector")),
			new DSDataSourceProvider(new EclipseExtensionReader("org.datascooter.dataSource")),
			new DSMappingProvider(new EclipseExtensionReader("org.datascooter.mapping")));
		DEFAULT = DataScooter.getDefault();
		EntityMapper.getBundle(Owner.class);
		EntityMapper.getBundle(Address.class);
		EntityMapper.getBundle(Phone.class);
		EntityMapper.getBundle(Location.class);
		TestUtils.clearAll(DEFAULT);
		DEFAULT.delete(ContextTestClassInt.class.getName());
		for (int a = 0; a less maxNum; a++) {
			list.add(new ContextTestClassInt(1000, Long.valueOf(a + 1)));
		}
		System.out.println("Size of item:  " + TestUtils.sizeOf(list.get(0)));
		startMemoryUse = TestUtils.getMemoryUse();
		System.out.println("Start Memory use:  " + startMemoryUse);
	}

	@Test
	public void a_save() throws Exception {
		DEFAULT.saveAll(list);
	}

	@Test
	public void b_select() throws Exception {
		snip = DEFAULT.retrieve(DataSnip.select(ContextTestClassInt.class));
		assertTrue("Size: " + snip.getData().length + "---" + list.size(), snip.getData().length == list.size());
	}

	@Test
	public void c_clear() throws Exception {
		DEFAULT.delete(ContextTestClassInt.class.getName());
	}

	@Test
	public void d_saveBatch() throws Exception {
		DEFAULT.executeAs(snip, SnipType.INSERT);
		int count = DEFAULT.count(ContextTestClassInt.class);
		assertTrue("Count: " + snip.getData().length + "---" + count, snip.getData().length == count);
	}

	@AfterClass
	public static void tearDown() throws Exception {
		endMemoryUse = TestUtils.getMemoryUse();
		System.out.println("Stop Memory use:  " + endMemoryUse);
		long memory = endMemoryUse - startMemoryUse;
		float approximateSize = memory / maxNum;
		System.out.println("Memory use :  " + memory);
		System.out.println("Scooter eats on each object :  " + Math.round(approximateSize));
		DEFAULT.delete(ContextTestClassInt.class.getName());
	}
}

	
	



Test execution results for Hibernate
Captute

Test execution results for Datascooter
Captute
So as we can see - Datascooter is faster and simpler.


YourKit is kindly supporting open source projects with its full-featured Java Profiler. YourKit, LLC is the creator of innovative and intelligent tools for profiling Java and .NET applications. Take a look at YourKit's leading software products: YourKit Java Profiler and YourKit .NET Profiler