So, in yesterday's post I compared structs vs components in a speed test. I thought I would expand the test to include adding rows to a query and creating Java objects.

The code I did is just an expansion of yesterday's and is as follows:

Object Speed Test

<!--- on the first round this file doesnt exist ---> <cfif fileExists(expandpath("createObject.log"))> <cffile action="delete" file="#expandpath("createObject.log")#"> <cffile action="append" file="#expandpath("createObject.log")#" output="Instances,Structure,Component,Recorset,JavaObject"> <!--- lets loop this crazyness---> .

<!--- arrays to fill--->

<!--- create a struct ---> <cfset stItem.name = "Bob" & i> <cfset ArrayAppend(stArray,stItem)> <cfset tTotalStruct = GetTickCount() - tStartStruct>

<!--- create an component ---> <cfset oItem = CreateObject('component', 'Person')> <cfset oItem.setname("Bob" & i )> <cfset oItem.setage(20)> <cfset ArrayAppend(oArray,oItem)> <cfset tTotalComponent = GetTickCount() - tStartComponent>

<!--- ---> <cfset qSampleQuery = QueryNew("name,age", "VarChar,Integer")> <cfset QueryAddRow(qSampleQuery)> <cfset QuerySetCell(qSampleQuery, "name", "bob" & i)> <cfset QuerySetCell(qSampleQuery, "age", 20)>

<cfset tTotalRecordSet = GetTickCount() - tStartRecordset>

<cfset oPerson = CreateObject("java", "uk.co.markdrew.cfml.test.Person").init()> <cfset oPerson.setName("bob" & i)> <cfset oPerson.setAge(20)> <cfset ArrayAppend(jArray, oPerson)>

<cfset tTotalObject = GetTickCount() - tStartObject>

<!--- log the times for this iteration ---> <cffile action="append" file="#expandpath("createObject.log")#" output="#x#,#tTotalStruct#,#tTotalComponent#,#tTotalRecordSet#,#tTotalObject#">

<!--- always flush once you have been there ---> | done!

Just for clarification, the java object that its instantiating is on the classpath already and the code for it is as follows :

package uk.co.markdrew.cfml.test;

public class Person {

private String name; private int age; public Person() { super(); // TODO Auto-generated constructor stub } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getName() { return name; } public void setName(String name) { this.name = name; }

}

Here is a chart of the results. If anyone has comments about my methodology, let me know, and I shall amend the test case as required.

EDIT: I was forgetting to add the objects to the array, although this is academic since that should be a very fast function. I shall re-run the test with the modifed code.