[rules-users] Performance of collect seems to be n-squared

Wolfgang Laun wolfgang.laun at gmail.com
Mon Feb 13 14:59:20 EST 2012


Repeatedly creating this ArrayList is bound to be O(n2).

Why do you want the Post facts as a List? There may be better ways for
achieving your goal.

-W


On 13 February 2012 20:49, Shur, Bob <robert.shur at hp.com> wrote:

> I have a simple class Post { int id; ... }. I insert some number of them
> as facts and then call ksession.execute(facts);
>
> The whole drl file (except for package and import statements) is:
>
> rule "collect"
> when
>        $a : ArrayList(size > 0) from collect(Post());
> then
>        System.out.println("Number of posts: " + $a.size());
>        System.out.println("DONE");
> end
>
> The time it takes to run is n-squared in the number of posts. For 4000,
> 8000, 16000, 32000, 64000 posts the time is (in 1/10 seconds):
>
> 4, 14, 56, 220, 852
>
> Is this expected? Is there a better way for me to do the collect?
>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20120213/323161b1/attachment.html 


More information about the rules-users mailing list