XPAGES – Is SSJS performance loss when using @functions?

If I want to parse text fields in SSJS, there are two main tools. Built-in JavaScript code and newly converted @Functions. Is @Functions slower than using pure javascript? Or is there no real difference?

viewScope.put("length", tmpStr.length)

and

viewScope.put("length:, @Length(tmpStr))

For me, It seems that @Formula is not as fast as using SSJS code.

You can easily test with code like this (reload the page multiple times to get serious results):





var start = java. lang.System.currentTimeMillis();
var testString = "0123456789";
var dummy;
for( var i=0; i<100000; i++ ){
dummy = @Length( testString )
}
var stop = java.lang.System.currentTimeMillis();
stop-start + "ms"}]]>






var start = java.lang.System.currentTimeMillis();
var testString = "0123456789";
var dummy;
for( var i=0; i<100000; i++ ){
dummy = testString.length;
}
var stop = java.lang .System.currentTimeMillis();
stop-start + "ms"}]]>


If I want to parse text fields in SSJS, there are two main tools. Built-in JavaScript code and newly converted @Functions. @Functions is better than Is it slow to use pure javascript? Or is there no real difference?

viewScope.put("length", tmpStr.length)

and

viewScope.put("length:, @Length(tmpStr))

For me, it seems that @Formula is not as fast as using SSJS code.

You can easily test with code like this (reload the page multiple times to get serious results):





var start = java.lang.System.currentTimeMillis();
var testString = "0123456789";
var dummy;
for( var i=0; i<100000; i++ ){
dummy = @Length( testString )
}
var stop = java.lang.System.currentTimeMillis();
stop-start + "ms"}]]>






var start = java.lang.System.currentTimeMillis();
var testString = "0123456789";
var dummy;
for( var i=0; i< 100000; i++ ){
dummy = testString.length;
}
var stop = java.lang.System.currentTimeMillis();
stop-start + "ms"}] ]>


Leave a Comment

Your email address will not be published.