{ "metadata": { "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": 3 }, "orig_nbformat": 2, "kernelspec": { "name": "julia-1.5", "display_name": "Julia 1.5.3", "language": "julia" } }, "nbformat": 4, "nbformat_minor": 2, "cells": [ { "source": [ "# Benchmarks\n", "This notebook compares the wrapped Fortran SLATEC implementation contained in `py3nj` with the native Julia `WignerFamilies.jl`. I use very high quantum numbers for this test, in order to amortize the cost of calling SLATEC with some Python overhead." ], "cell_type": "markdown", "metadata": {} }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "WignerFamilies.jl: 619.900 μs (0 allocations: 0 bytes)\n", "SLATEC wrapper: 1.637 ms (83 allocations: 2.44 MiB)\n" ] } ], "source": [ "using WignerFamilies\n", "using PyCall\n", "using BenchmarkTools\n", "py3nj = pyimport(\"py3nj\")\n", "\n", "j₂, j₃, m₂, m₃ = 40000, 40000, -2, 2\n", "w = WignerF(Float64, j₂, j₃, m₂, m₃)\n", "w3j = get_wigner_array(w)\n", "\n", "print(\"WignerFamilies.jl: \")\n", "@btime WignerFamilies.wigner3j_f!(w, w3j)\n", "print(\"SLATEC wrapper: \")\n", "@btime two_l1, three_j = py3nj.wigner.drc3jj(2j₂, 2j₃, 2m₂, 2m₃);" ] }, { "source": [ "## Comparing Allocating Versions\n", "\n", "This is perhaps a more fair test, since the wrapped SLATEC is allocating each time." ], "cell_type": "markdown", "metadata": {} }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "WignerFamilies.jl: 652.100 μs (3 allocations: 625.17 KiB)\n", "SLATEC wrapper: 1.671 ms (83 allocations: 2.44 MiB)\n" ] } ], "source": [ "print(\"WignerFamilies.jl: \")\n", "@btime WignerFamilies.wigner3j_f(Float64, j₂, j₃, m₂, m₃);\n", "print(\"SLATEC wrapper: \")\n", "@btime two_l1, three_j = py3nj.wigner.drc3jj(2j₂, 2j₃, 2m₂, 2m₃);" ] }, { "source": [ "## m_i = 0\n", "\n", "WignerFamilies.jl uses a special case for `m_i = 0` that gives it an extra factor of 2.\n" ], "cell_type": "markdown", "metadata": {} }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "WignerFamilies.jl: 387.400 μs (3 allocations: 625.17 KiB)\n", "SLATEC wrapper: 1.673 ms (83 allocations: 2.44 MiB)\n" ] } ], "source": [ "j₂, j₃, m₂, m₃ = 40000, 40000, 0, 0\n", "print(\"WignerFamilies.jl: \")\n", "@btime WignerFamilies.wigner3j_f(Float64, j₂, j₃, m₂, m₃);\n", "print(\"SLATEC wrapper: \")\n", "@btime two_l1, three_j = py3nj.wigner.drc3jj(2j₂, 2j₃, 2m₂, 2m₃);" ] } ] }