NSArray-LongestCommonSubsequence icon indicating copy to clipboard operation
NSArray-LongestCommonSubsequence copied to clipboard

speed?

Open Janneman84 opened this issue 9 years ago • 1 comments

I just tried this and it works well, however it's not very fast with large collections.

I'm sure it has to do with having an array of 1150 ints that I like to diff. It takes a couple of seconds on my iPad. Is this to be expected?

Janneman84 avatar Jan 10 '17 11:01 Janneman84

I don't think it should take quite that long with only 1,000 items. It's an n² algorithm, so about 1,000,000 operations, but each iteration of the array is pretty fast. See the code here:

https://github.com/khanlou/NSArray-LongestCommonSubsequence/blob/master/LongestCommonSubsequence/NSArray%2BLongestCommonSubsequence.m#L37-L48

I would recommend using instruments or something to profile your code?

khanlou avatar Jan 10 '17 13:01 khanlou