Last active
October 13, 2017 13:52
-
-
Save kalmarek/d80efa6cf0425168f767cb9c2c3f3f20 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
using Nemo | |
using BenchmarkTools | |
function perm_sample(N=1000, samplesize=10000, seed=1234) | |
sample = Nemo.Generic.perm[] | |
srand(seed) | |
for i in 1:samplesize | |
push!(sample, rand(PermutationGroup(N))) | |
end | |
return sample | |
end | |
parity_new(a::Nemo.Generic.perm) = sum([(length(c)+1)%2 for c in cycles(a)])%2 | |
function par() | |
for p in perm_sample() | |
parity(p) | |
end | |
end | |
function par_new() | |
for p in perm_sample() | |
parity_new(p) | |
end | |
end | |
perms = perm_sample(); | |
@assert parity.(perms) == parity_new.(perms) | |
par() | |
orig = @benchmark par() | |
par_new() | |
new = @benchmark par_new(); | |
display(orig) | |
println("") | |
display(new) | |
println("") | |
display(judge(median(new), median(orig))) | |
println("") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment