DATASCOOTER
Support This Project
Custom Search

English Home
Russian Home
JavaDoc
Quickstart
Download
Example
Performance
Contacts

Performance Comparison

Let's compare a performance of Datascooter-2.7(Will be wery soon) and Hibernate-3. The task for both - save,select, delete and save again into MySQl database 10000 objects of class ContextTestClass. For Hibernate it looks like:
	    
@Entity
@Table(name = "CONTEXT_TEST")
public class ContextTestClass 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 ContextTestClass() {
	}

	public Long getId() {
		return id;
	}

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

	public ContextTestClass(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;
	}
}
	 
For Datascooter it looks like:
	 /**
 * 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 ContextTestClass implements Serializable {

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

	public ContextTestClass() {
	}

	public ContextTestClass(Integer size) throws UnsupportedEncodingException {
		this.id = UUID.randomUUID().toString();
		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 getId() {
		return id;
	}

	public void setId(String 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 = 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:
	
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 ContextTestClass(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 " + ContextTestClass.class.getName());
		openSession.getTransaction().commit();
	}

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

	@SuppressWarnings("unchecked")
	@Test
	public void b_select() throws Exception {
		openSession.beginTransaction();
		list2 = openSession.createQuery("FROM " + ContextTestClass.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 " + ContextTestClass.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 " +
		// ContextTestClass.class.getName()).executeUpdate();
		// openSession.getTransaction().commit();
	}
}
	
	
The test case for Datascooter:
 
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();
		TestUtils.clearAll(DEFAULT);
		DEFAULT.delete(ContextTestClass.class.getName());
		for (int a = 0; a less maxNum; a++) {
			list.add(new ContextTestClass(1000));
		}
		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(ContextTestClass.class.getName()));
		assertTrue("Size: " + snip.getData().length + "---" + list.size(), snip.getData().length == list.size());
	}

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

	@Test
	public void d_saveBatch() throws Exception {
		DEFAULT.executeAs(snip, SnipType.INSERT);
		int count = DEFAULT.count(ContextTestClass.class.getName());
		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(ContextTestClass.class.getName());
	}
}
	
	


Test execution results for Hibernate:
Captute
Test execution results for Hibernate - console view:
Captute
Test execution results for Datascooter:

Captute
Test execution results for Datascooter - console view:
Captute
So as we can see - Datascooter is faster and creates smaller overheads of memory for transfer of each object.