Last active
April 26, 2020 13:11
-
-
Save JeffreySarnoff/5812f56decfecc430050bd6cce6fa025 to your computer and use it in GitHub Desktop.
benchmarks used to compare the PR for `rational.jl` with the current `rational.jl`
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 LinearAlgebra | |
#= | |
you set this directory with the const or through the environment | |
ensure RelativeSpeeds.jl and Fractions.jl are kept there | |
=# | |
const DefaultBenchmarkingDir = pwd() | |
benchmarking_dir = haskey(ENV, "BenchmarkingDir") ? ENV["BenchmarkingDir"] : DefaultBenchmarkingDir | |
cd(benchmarking_dir) | |
include("RelativeSpeeds.jl") | |
include("Fractions.jl") | |
using .Fractions | |
#= | |
the first 256 composite5 numbers | |
2*3*5*7*11 and 2^3 * 3^3 * 5^1 * 7^1 * 19^1 are examples | |
=# | |
const composite5 = [ | |
2310, 2730, 3570, 3990, 4290, 4620, 4830, 5460, 5610, 6006, 6090, 6270, | |
6510, 6630, 6930, 7140, 7410, 7590, 7770, 7854, 7980, 8190, 8580, 8610, | |
8778, 8970, 9030, 9240, 9282, 9570, 9660, 9690, 9870, 10010, 10230, | |
10374, 10626, 10710, 10920, 11130, 11220, 11310, 11550, 11730, 11970, | |
12012, 12090, 12180, 12210, 12390, 12540, 12558, 12810, 12870, 13020, | |
13090, 13110, 13260, 13398, 13530, 13566, 13650, 13860, 14070, 14190, | |
14280, 14322, 14430, 14490, 14586, 14630, 14790, 14820, 14910, 15015, | |
15180, 15330, 15470, 15510, 15540, 15708, 15810, 15834, 15960, 15990, | |
16170, 16302, 16380, 16422, 16530, 16590, 16770, 16830, 16926, 17094, | |
17160, 17220, 17290, 17430, 17490, 17556, 17670, 17710, 17850, 17940, | |
18018, 18060, 18270, 18330, 18354, 18480, 18564, 18690, 18810, 18870, | |
18942, 19110, 19140, 19320, 19380, 19470, 19530, 19635, 19734, 19740, | |
19866, 19890, 19950, 20010, 20020, 20130, 20202, 20370, 20460, 20670, | |
20706, 20748, 20790, 20910, 20930, 21090, 21210, 21252, 21318, 21390, | |
21420, 21450, 21630, 21714, 21840, 21930, 21945, 22110, 22134, 22230, | |
22260, 22330, 22386, 22440, 22470, 22610, 22620, 22770, 22890, 23010, | |
23100, 23142, 23205, 23310, 23370, 23430, 23460, 23478, 23562, 23730, | |
23790, 23870, 23940, 23970, 24024, 24090, 24150, 24180, 24310, 24360, | |
24420, 24486, 24510, 24570, 24738, 24780, 24882, 24990, 25080, 25116, | |
25194, 25410, 25530, 25620, 25662, 25740, 25806, 25830, 25935, 26040, | |
26070, 26130, 26180, 26220, 26334, 26390, 26418, 26520, 26565, 26598, | |
26670, 26790, 26796, 26910, 26970, 27030, 27060, 27090, 27132, 27170, | |
27258, 27300, 27370, 27390, 27510, 27690, 27720, 27846, 27930, 28014, | |
28050, 28140, 28182, 28210, 28290, 28380, 28470, 28490, 28560, 28644, | |
28710, 28770, 28842, 28860, 28938, 28980, 29070, 29172, 29190, 29260, | |
29274 | |
]; | |
const rationals256 = composite5 .// reverse(composite5); | |
const fractions256 = composite5 .⨸ reverse(composite5); | |
const rationals64 = rationals256[96:159] | |
const fractions64 = fractions256[96:159] | |
const rationals16 = rationals256[120:135] | |
const fractions16 = fractions256[120:135] | |
const rationals4 = rationals256[126:129] | |
const fractions4 = fractions256[126:129] | |
const rationals2 = rationals256[127:2:129] | |
const fractions2 = fractions256[127:2:129] | |
const rationals1 = rationals256[64] | |
const fractions1 = fractions256[64] | |
const rationals16x16 = Rational{BigInt}.(reshape(rationals256, 16, 16)) | |
const fractions16x16 = Rational{BigInt}.(reshape(fractions256, 16, 16)) | |
const rationals8x8 = Rational{BigInt}.(reshape(rationals64, 8, 8)) | |
const fractions8x8 = Rational{BigInt}.(reshape(fractions64, 8, 8)) | |
const rationals4x4 = Rational{Int128}.(reshape(rationals16, 4, 4)) | |
const fractions4x4 = Rational{Int128}.(reshape(fractions16, 4, 4)) | |
const rationals2x2 = Rational{Int64}.(reshape(rationals4, 2, 2)) | |
const fractions2x2 = Rational{Int64}.(reshape(fractions4, 2, 2)) | |
#= | |
relspeed | |
relspeed | interpretation | |
---------|--------------- | |
1.0 | no change in performance | |
1.5 | what took 3 time units now takes 2 (3/2 == 1.5) | |
2.0 | what took 2 time units now takes 1 | |
2.5 | what took 5 time units now takes 2 | |
=# | |
relspeed(x->x[1] + x[2], rationals2, fractions2) # 1.0 | |
relspeed(x->x[1] - x[2], rationals2, fractions2) # 1.0 | |
relspeed(x->x[1] * x[2], rationals2, fractions2) # 1.6 | |
relspeed(x->x[1] / x[2], rationals2, fractions2) # 1.55 | |
relspeed(inv, rationals1, fractions1) # 2.8 | |
relspeed(prod, rationals4, fractions4) # 1.5 | |
relspeed(prod, rationals16, fractions16) # 1.6 | |
relspeed(prod, Rational{Int128}.(rationals64), Fraction{Int128}.(fractions64)) # 1.4 | |
relspeed(prod, Rational{BigInt}.(rationals256), Fraction{BigInt}.(fractions256)) # 1.4 | |
relspeed(x->inv.(x), rationals4, fractions4) # 2.1 | |
relspeed(x->inv.(x), rationals16, fractions16) # 2.4 | |
relspeed(x->inv.(x), rationals64, fractions64) # 2.6 | |
relspeed(x->inv.(x), rationals256, fractions256) # 2.8 | |
relspeed(dot, rationals4, rationals4, fractions4, fractions4) # 1.2 | |
relspeed(dot, Rational{BigInt}.(rationals16), Rational{BigInt}.(rationals16), | |
Fraction{BigInt}.(fractions16), Fraction{BigInt}.(fractions16) ) # 1.0 | |
relspeed(*, rationals16x16, rationals16x16, fractions16x16, fractions16x16) # 1.0 | |
relspeed(+, rationals4x4, rationals4x4, fractions4x4, fractions4x4) # 1.0 | |
relspeed(inv, rationals4x4, fractions4x4) # 1.0 | |
relspeed(inv, rationals2x2, fractions2x2) # 1.0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment