N
NOBODY
Hi,
About rules engines (and jsr-94):
We looked at 'drools', but it uses method invocations.
---> Is there other implementations around, not based on method
invocation?
Given that invocation is 50 to 300 times slower than compiled call,
method invocation sucks big time at high throughputs. My only alternative
is code generation at this point.
Thanks.
-------test code to show invocation cost-------
package tests;
import java.lang.reflect.Method;
public class TestInvokeSpeed {
static Method m_dovoid;
static Method m_dolong;
static Method m_dolongw;
static {
try {
m_dovoid = TestInvokeSpeed.class.getMethod("dovoid", new
Class[]{});
System.out.println(m_dovoid);
m_dolong = TestInvokeSpeed.class.getMethod("dolong", new
Class[]{Long.TYPE, Long.TYPE, String.class, String.class});
System.out.println(m_dolong);
m_dolongw = TestInvokeSpeed.class.getMethod("dolongw",
new Class[]{Long.class, Long.class, String.class, String.class});
System.out.println(m_dolongw);
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws Exception {
int N=40*1000*1000;
testvoid(false, N); System.out.println();
testlong(false, N); System.out.println();
testlongw(false, N); System.out.println();
testvoid(true, N); System.out.println();
testlong(true, N); System.out.println();
testlongw(true, N); System.out.println();
}
static void testvoid(boolean echo, int N) throws Exception {
long t1, d1, d2, d3;
t1 = System.currentTimeMillis();
for(int i=0; i<N; i++) {
dovoid();
}
d1 = System.currentTimeMillis()-t1;
System.out.print(!echo?".":"direct dovoid: total="+d1
+" ms, avg="+(1000.0*d1/N)+" us\n");
t1 = System.currentTimeMillis();
for(int i=0; i<N; i++) {
m_dovoid.invoke(null, null);
}
d2 = System.currentTimeMillis()-t1;
System.out.print(!echo?".":"invoke dovoid+null: total="+d2
+" ms ("+(1.0*d2/d1)+"x), avg="+(1000.0*d2/N)+" us\n");
Object[] args = new Object[0];
t1 = System.currentTimeMillis();
for(int i=0; i<N; i++) {
m_dovoid.invoke(null, args);
}
d3 = System.currentTimeMillis()-t1;
System.out.print(!echo?".":"invoke dovoid: total="+d3
+" ms ("+(1.0*d3/d1)+"x), avg="+(1000.0*d3/N)+" us\n");
}
static void testlong(boolean echo, int N) throws Exception {
long t1, d1, d2;
t1 = System.currentTimeMillis();
for(int i=0; i<N; i++) {
long l = dolong(1, 2, "toto", "tata");
}
d1 = System.currentTimeMillis()-t1;
System.out.print(!echo?".":"direct dolong: total="+d1
+" ms, avg="+(1000.0*d1/N)+" us\n");
Object[] args = new Object[]{new Long(1), new Long(2), "toto",
"tata"};
t1 = System.currentTimeMillis();
for(int i=0; i<N; i++) {
long l = ((Long)m_dolong.invoke(null, args)).longValue();
}
d2 = System.currentTimeMillis()-t1;
System.out.print(!echo?".":"invoke dolong: total="+d2
+" ms ("+(1.0*d2/d1)+"x), avg="+(1000.0*d2/N)+" us\n");
}
static void testlongw(boolean echo, int N) throws Exception {
long t1, d1, d2;
Long l1 = new Long(1);
Long l2 = new Long(2);
t1 = System.currentTimeMillis();
for(int i=0; i<N; i++) {
Long l = dolongw(l1, l2, "toto", "tata");
}
d1 = System.currentTimeMillis()-t1;
System.out.print(!echo?".":"direct dolongw: total="+d1
+" ms, avg="+(1000.0*d1/N)+" us\n");
Object[] args = new Object[]{new Long(1), new Long(2), "toto",
"tata"};
t1 = System.currentTimeMillis();
for(int i=0; i<N; i++) {
Long l = (Long)m_dolong.invoke(null, args);
}
d2 = System.currentTimeMillis()-t1;
System.out.print(!echo?".":"invoke dolongw: total="+d2
+" ms ("+(1.0*d2/d1)+"x), avg="+(1000.0*d2/N)+" us\n");
}
public static void dovoid() {}
public static long dolong(long l1, long l2, String s1, String s2) {
return 0;
}
public static Long dolongw(Long l1, Long l2, String s1, String s2) {
return null;
}
}
About rules engines (and jsr-94):
We looked at 'drools', but it uses method invocations.
---> Is there other implementations around, not based on method
invocation?
Given that invocation is 50 to 300 times slower than compiled call,
method invocation sucks big time at high throughputs. My only alternative
is code generation at this point.
Thanks.
-------test code to show invocation cost-------
package tests;
import java.lang.reflect.Method;
public class TestInvokeSpeed {
static Method m_dovoid;
static Method m_dolong;
static Method m_dolongw;
static {
try {
m_dovoid = TestInvokeSpeed.class.getMethod("dovoid", new
Class[]{});
System.out.println(m_dovoid);
m_dolong = TestInvokeSpeed.class.getMethod("dolong", new
Class[]{Long.TYPE, Long.TYPE, String.class, String.class});
System.out.println(m_dolong);
m_dolongw = TestInvokeSpeed.class.getMethod("dolongw",
new Class[]{Long.class, Long.class, String.class, String.class});
System.out.println(m_dolongw);
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws Exception {
int N=40*1000*1000;
testvoid(false, N); System.out.println();
testlong(false, N); System.out.println();
testlongw(false, N); System.out.println();
testvoid(true, N); System.out.println();
testlong(true, N); System.out.println();
testlongw(true, N); System.out.println();
}
static void testvoid(boolean echo, int N) throws Exception {
long t1, d1, d2, d3;
t1 = System.currentTimeMillis();
for(int i=0; i<N; i++) {
dovoid();
}
d1 = System.currentTimeMillis()-t1;
System.out.print(!echo?".":"direct dovoid: total="+d1
+" ms, avg="+(1000.0*d1/N)+" us\n");
t1 = System.currentTimeMillis();
for(int i=0; i<N; i++) {
m_dovoid.invoke(null, null);
}
d2 = System.currentTimeMillis()-t1;
System.out.print(!echo?".":"invoke dovoid+null: total="+d2
+" ms ("+(1.0*d2/d1)+"x), avg="+(1000.0*d2/N)+" us\n");
Object[] args = new Object[0];
t1 = System.currentTimeMillis();
for(int i=0; i<N; i++) {
m_dovoid.invoke(null, args);
}
d3 = System.currentTimeMillis()-t1;
System.out.print(!echo?".":"invoke dovoid: total="+d3
+" ms ("+(1.0*d3/d1)+"x), avg="+(1000.0*d3/N)+" us\n");
}
static void testlong(boolean echo, int N) throws Exception {
long t1, d1, d2;
t1 = System.currentTimeMillis();
for(int i=0; i<N; i++) {
long l = dolong(1, 2, "toto", "tata");
}
d1 = System.currentTimeMillis()-t1;
System.out.print(!echo?".":"direct dolong: total="+d1
+" ms, avg="+(1000.0*d1/N)+" us\n");
Object[] args = new Object[]{new Long(1), new Long(2), "toto",
"tata"};
t1 = System.currentTimeMillis();
for(int i=0; i<N; i++) {
long l = ((Long)m_dolong.invoke(null, args)).longValue();
}
d2 = System.currentTimeMillis()-t1;
System.out.print(!echo?".":"invoke dolong: total="+d2
+" ms ("+(1.0*d2/d1)+"x), avg="+(1000.0*d2/N)+" us\n");
}
static void testlongw(boolean echo, int N) throws Exception {
long t1, d1, d2;
Long l1 = new Long(1);
Long l2 = new Long(2);
t1 = System.currentTimeMillis();
for(int i=0; i<N; i++) {
Long l = dolongw(l1, l2, "toto", "tata");
}
d1 = System.currentTimeMillis()-t1;
System.out.print(!echo?".":"direct dolongw: total="+d1
+" ms, avg="+(1000.0*d1/N)+" us\n");
Object[] args = new Object[]{new Long(1), new Long(2), "toto",
"tata"};
t1 = System.currentTimeMillis();
for(int i=0; i<N; i++) {
Long l = (Long)m_dolong.invoke(null, args);
}
d2 = System.currentTimeMillis()-t1;
System.out.print(!echo?".":"invoke dolongw: total="+d2
+" ms ("+(1.0*d2/d1)+"x), avg="+(1000.0*d2/N)+" us\n");
}
public static void dovoid() {}
public static long dolong(long l1, long l2, String s1, String s2) {
return 0;
}
public static Long dolongw(Long l1, Long l2, String s1, String s2) {
return null;
}
}