apriori.js icon indicating copy to clipboard operation
apriori.js copied to clipboard

benefit dictionary lookup instead of foreach

Open bacloud23 opened this issue 5 years ago • 4 comments

Heyy

Thanks for this amazing code.

I am using it and thought let's look at performance profiler, most execution time is in two nested for-each loops. You can benefit dictionary lookup here.

Result: Much gain !

Note: I don't know anything about packaging JavaScript apps, bower or even how you are testing stuff. I assume you change accordingly if you agree.

Thanks again (I am using this somewhere in my repos).

bacloud23 avatar Aug 31 '20 11:08 bacloud23

in

ArrayUtils.isSubSetArrayOf = function(targetArray, superSetArray) {
	var isSubSetArray = true;
	targetArray.forEach(function(item) {
		if (isSubSetArray && superSetArray.indexOf(item) === -1)
			isSubSetArray = false;
	});
	return isSubSetArray;
};

You may also consider sorting before checking if all elements of targetArray are in superSetArray. My intuition says it would be faster.

Kindly see the solution here: https://stackoverflow.com/a/8628118/9164621

ghost avatar Aug 31 '20 12:08 ghost

edit:

I tested the solution using sorting, it turned out very greedy. I think sort of Strings in Javascript is very greedy.

ghost avatar Aug 31 '20 12:08 ghost

@bacloud14 Hi, thanks for your interest in this library! It seems your improvement should be valid and should be applied. However, this project is so old that we need to start repairing the build config 😅 (getting rid of Grunt, and so on - probably).

Although I don't have the bandwidth to work on this project now, once we manage to fix the build settings and verify your change works, I'm happy to merge your improvement and ship a new version!

seratch avatar Aug 31 '20 14:08 seratch

ok, many thanks for your attention.

ghost avatar Aug 31 '20 14:08 ghost