class Test {
String field
int num
public Test (String field, int num) {
this.field = field
this.num = num
}
}
def start = System.currentTimeMillis()
def testObj = new Test("i'm field", 1)
println "Beans: ${System.currentTimeMillis() - start}"
def start2 = System.currentTimeMillis()
def map = [:]
map.field = "i'm field"
map.num = 1
println "Maps: ${System.currentTimeMillis() - start2}"
Output is:
Beans: 3
Maps: 0
My Grails server communicates over JSON. I'm using map <-> JSON conversion but i think it would be better to use beans because in maps case you have to call numerous put() methods...
But simple script shows that Map creating and two put operations are faster than simple object constructor...
So would i continue using maps or beans are preferable ?