Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a lot of manual loops instead of findfirst in project! and others #42

Open
Krastanov opened this issue Mar 24, 2022 · 0 comments
Open
Labels
code quality Code that should be refactored

Comments

@Krastanov
Copy link
Member

Weirdly, findfirst seems slower...

function f1(stabilizer, qubit)
    anticommutes = 0
    r = length(stabilizer)
    for i in 1:r # The explicit loop is faster than anticommutes = findfirst(row->comm(pauli,stabilizer,row)!=0x0, 1:r); both do not allocate.
        if isZ(stabilizer,i,qubit)
            anticommutes = i
            break
        end
    end
    return anticommutes
end

function f2(stabilizer, qubit)
    r = length(stabilizer)
    findfirst(i->isZ(stabilizer,i,qubit), 1:r)
end
##
N = 1000
s = ghz(N);
##
@benchmark f1(_s, N) setup=(_s=copy(s))
##
@benchmark f2(_s, N) setup=(_s=copy(s))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code quality Code that should be refactored
Projects
None yet
Development

No branches or pull requests

1 participant