Olá pessoal,
Fiz mais alguns testes com os scripts e tenho alguns resultados a postar para discurssões.
Nos testei usei um Pentium 4 com HyperThread 3ghz com 2Gb de memória e durante este período apenas a aplicação do teste estava sendo executada. Apesar do HyperThread, a JVM só usou 50% do processamento, isso por que ela não aloca automaticamente o outro processador, mas enfim.
A situação do teste foi semelhante a uma situação sem loops porém com uso de testes condicionais. Isso por que para minha aplicação é o que deverei utilizar ao contrário de scripts muito longos com loops longos.
Gostaria de comentar o consumo de memória. Para este teste o LUA chegou a consumir 63MB, o Groovy 160MB e o Caju, Incríveis 13MB. O gerenciamento do Caju me pareceu bastante bom, o LuaJava tem problemas realmente no gerenciamento de sua memória, pois o consumo aumenta linearmente com o numero de interações ( para um milhão de interações ele chegou a consumir 1GB ). Em contato com os desenvolvedores do LUA eles assumiram a falha e deverá ser corrigida na próxima versão. Diferentemente, o CajuScript se manteve estável independente do número de interações processadas.
Para um script que roda 100% dentro da plataforma JAVA o CajuScript tem um desempenho MUITO BOM. O LUA é realmente bem mais rápido, mas precisa de uma DLL para funcionar.
O Groovy se demostrou muito pesado e o gerenciamento da memória não me pareceu satisfatório, vou postar o código fonte e se alguem souber uma forma de melhorar este desempenho que poste seus comentários aqui. O Groovy me pareceu bom quando o script tem bastante loops demorados, mas para aplicações que precisam processar muitas vezes com curtos scripts ele não se demonstrou adequado.
O LUA não trata ainda array nativos do JAVA então fui obrigado a por o Array dentro do ArrayList e passar o objeto inteiro, porém isso deixou o LUA em desvantagem pois contabilizei este tempo como processamento do script. Mesmo assim o LUA por ser executado diretamente por uma DLL tem o desempenho muito bom.
Código fonte Utilizado para teste:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package testecajuscript;
import java.util.ArrayList;
import javax.script.ScriptException;
import org.keplerproject.luajava.LuaState;
/**
*
* @author user
*/
public class ScriptsTester {
public static void main(String[] args) {
try {
System.out.println("======================");
System.out.println("Scripts Tester");
System.out.println("======================");
//testeLua(1000000);
//testeCaju(100000);
testeGroovy(100000);
} catch (Exception e) {
throw new Error(e);
}
}
public static void testeCaju(int interacoes) throws ScriptException {
long time = 0;
String colunas[] = {"ZZ", "XX", "CC", "VV", "TT", "YY", "UU", "QQ", "WW", "EE", "RR"};
String scriptCaju = "caju.cache test;";
scriptCaju += "array.get(colunas, 0) = 'ZZ' ? array.set(colunas, 0, 'VALOR'); ?;";
scriptCaju += "array.get(colunas, 1) = 'XX' ? array.set(colunas, 1, 'VALOR'); ?;";
scriptCaju += "array.get(colunas, 2) = 'CC' ? array.set(colunas, 2, 'VALOR'); ?;";
scriptCaju += "array.get(colunas, 3) = 'VV' ? array.set(colunas, 3, 'VALOR'); ?;";
scriptCaju += "array.get(colunas, 4) = 'TT' ? array.set(colunas, 4, 'VALOR'); ?;";
scriptCaju += "array.get(colunas, 5) = 'YY' ? array.set(colunas, 5, 'VALOR'); ?;";
scriptCaju += "array.get(colunas, 6) = 'UU' ? array.set(colunas, 6, 'VALOR'); ?;";
scriptCaju += "array.get(colunas, 7) = 'QQ' ? array.set(colunas, 7, 'VALOR'); ?;";
scriptCaju += "array.get(colunas, 8) = 'WW' ? array.set(colunas, 8, 'VALOR'); ?;";
scriptCaju += "array.get(colunas, 9) = 'EE' ? array.set(colunas, 9, 'VALOR'); ?;";
scriptCaju += "array.get(colunas, 10) = 'RR' ? array.set(colunas, 10, 'VALOR'); ?;";
/* Teste CajuScript */
System.out.println("\n---------------- CajuScript ------------------");
time = System.currentTimeMillis();
javax.script.ScriptEngine caju = new org.cajuscript.CajuScriptEngine();
for (int i = 0; i < interacoes; i++) {
caju.put("colunas", colunas);
caju.eval(scriptCaju);
if (i == 1 || i == 100 || i == 1000 || (i >= 10000 && (i % 10000) == 0)) {
System.out.println("Interações: " + i + " Tempo: " + (System.currentTimeMillis() - time) + "ms");
}
}
System.out.println("Interações Totais: " + interacoes + " Tempo Total: " + (System.currentTimeMillis() - time) + "ms ");
}
public static void testeGroovy(int interacoes) {
long time = 0;
String colunas[] = {"ZZ", "XX", "CC", "VV", "TT", "YY", "UU", "QQ", "WW", "EE", "RR"};
String scriptGroovy = "(colunas[0] == 'ZZ' ? 'VALOR' : ''); ";
scriptGroovy += "(colunas[1] == 'XX' ? 'VALOR' : ''); ";
scriptGroovy += "(colunas[2] == 'CC' ? 'VALOR' : ''); ";
scriptGroovy += "(colunas[3] == 'VV' ? 'VALOR' : ''); ";
scriptGroovy += "(colunas[4] == 'TT' ? 'VALOR' : ''); ";
scriptGroovy += "(colunas[5] == 'YY' ? 'VALOR' : ''); ";
scriptGroovy += "(colunas[6] == 'UU' ? 'VALOR' : ''); ";
scriptGroovy += "(colunas[7] == 'QQ' ? 'VALOR' : ''); ";
scriptGroovy += "(colunas[8] == 'WW' ? 'VALOR' : ''); ";
scriptGroovy += "(colunas[9] == 'EE' ? 'VALOR' : ''); ";
scriptGroovy += "(colunas[10] == 'RR' ? 'VALOR' : ''); ";
System.out.println("\n---------------- Groovy ------------------");
time = System.currentTimeMillis();
for (int i = 0; i < interacoes; i++) {
groovy.lang.GroovyShell groovyShell = new groovy.lang.GroovyShell();
groovyShell.setVariable("colunas", colunas);
groovyShell.evaluate(scriptGroovy);
if (i == 1 || i == 100 || i == 1000 || (i >= 10000 && (i % 10000) == 0)) {
System.out.println("Interações: " + i + " Tempo: " + (System.currentTimeMillis() - time) + "ms");
}
}
System.out.println("Interações Totais: " + interacoes + " Tempo Total: " + (System.currentTimeMillis() - time) + "ms ");
}
public static void testeLua(int interacoes) {
long time = 0;
String colunas[] = {"ZZ", "XX", "CC", "VV", "TT", "YY", "UU", "QQ", "WW", "EE", "RR"};
String scriptLua = "if array:get(0) == 'XX' then array:set(0,'VALOR') end";
scriptLua += "if array:get(1) == 'XX' then array:set(1,'VALOR') end";
scriptLua += "if array:get(2) == 'XX' then array:set(2,'VALOR') end";
scriptLua += "if array:get(3) == 'XX' then array:set(3,'VALOR') end";
scriptLua += "if array:get(4) == 'XX' then array:set(4,'VALOR') end";
scriptLua += "if array:get(5) == 'XX' then array:set(5,'VALOR') end";
scriptLua += "if array:get(6) == 'XX' then array:set(6,'VALOR') end";
scriptLua += "if array:get(7) == 'XX' then array:set(7,'VALOR') end";
scriptLua += "if array:get(8) == 'XX' then array:set(8,'VALOR') end";
scriptLua += "if array:get(9) == 'XX' then array:set(9,'VALOR') end";
scriptLua += "if array:get(10) == 'XX' then array:set(10,'VALOR') end";
/* Teste LuaScript */
System.out.println("\n---------------- LuaJava ------------------");
ArrayList array;
LuaState L;
time = System.currentTimeMillis();
array = new ArrayList();
for (int j = 0; j < colunas.length; j++) {
array.add(colunas[j]);
}
L = org.keplerproject.luajava.LuaStateFactory.newLuaState();
L.openLibs();
for (int i = 0; i < interacoes; i++) {
L.pushJavaObject(array);
L.setGlobal("array");
L.LdoString(scriptLua);
if (i == 1 || i == 100 || i == 1000 || (i >= 10000 && (i % 10000) == 0)) {
System.out.println("Interações: " + i + " Tempo: " + (System.currentTimeMillis() - time) + "ms");
}
L.pop(1);
}
System.out.println("Interações Totais: " + interacoes + " Tempo Total: " + (System.currentTimeMillis() - time) + "ms ");
}
}