Created
March 11, 2013 16:32
-
-
Save luqui/5135504 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.List | |
import qualified Data.Set as Set | |
import Criterion.Main | |
itemsEqualOnDiff :: (Eq a) => [a] -> [a] -> Bool | |
itemsEqualOnDiff [] [] = True | |
itemsEqualOnDiff [] _ = False | |
itemsEqualOnDiff _ [] = False | |
itemsEqualOnDiff (aHead:aTail) b = itemsEqualOnDiff aTail $ delete aHead b | |
itemsEqualOnSort :: (Eq a, Ord a) => [a] -> [a] -> Bool | |
itemsEqualOnSort a b = sort a == sort b | |
-- Note: produces incorrect results for lists with duplicate items | |
itemsEqualOnSet :: (Eq a, Ord a) => [a] -> [a] -> Bool | |
itemsEqualOnSet a b = Set.fromList a == Set.fromList b | |
shuf1 :: [Int] | |
shuf1 = [84,91,16,32,29,19,77,89,38,86,17,9,94,81,21,35,22,53,66,98,28,40,1,23,97,74,80,67,30,82,76,27,79,90,54,20,58,87,75,42,73,61,60,6,7,96,10,69,5,8,50,85,11,37,43,68,56,62,78,12,83,51,46,41,63,14,65,64,72,100,2,33,26,13,57,88,18,49,39,34,47,25,70,3,95,93,59,15,44,48,99,92,71,45,55,31,4,24,36,52] | |
shuf2 :: [Int] | |
shuf2 = [53,36,29,80,35,4,81,88,72,59,15,48,94,50,24,5,62,90,85,87,43,18,21,75,96,91,65,52,39,6,23,74,89,44,69,3,79,60,67,10,1,45,51,41,68,55,7,28,33,34,13,37,63,31,66,46,93,98,8,84,58,99,16,11,77,71,25,64,42,27,95,30,32,73,49,100,57,9,14,54,19,92,40,17,82,83,97,12,38,61,26,78,70,56,47,76,22,2,86,20] | |
main = | |
defaultMain [ | |
bgroup "[1,1,4,2,3,5] [3,4,1,5,2,1]" [ | |
bench "itemsEqualOnDiff" | |
$ nf (itemsEqualOnDiff [1,1,4,2,3,5]) [3,4,1,5,2,1], | |
bench "itemsEqualOnSort" | |
$ nf (itemsEqualOnSort [1,1,4,2,3,5]) [3,4,1,5,2,1], | |
bench "itemsEqualOnSet" | |
$ nf (itemsEqualOnSet [1,1,4,2,3,5]) [3,4,1,5,2,1] | |
], | |
bgroup "(shuffle [0..100]) (shuffle [0..100])" [ | |
bench "itemsEqualOnDiff" | |
$ nf (itemsEqualOnDiff shuf1) shuf2, | |
bench "itemsEqualOnSort" | |
$ nf (itemsEqualOnSort shuf1) shuf2, | |
bench "itemsEqualOnSet" | |
$ nf (itemsEqualOnSet shuf1) shuf2 | |
] | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment