Last active
August 29, 2015 14:22
-
-
Save oxinabox/a00d3b1eb5584467e6b7 to your computer and use it in GitHub Desktop.
unioning numerics
This file contains hidden or 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
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"self_square_a (generic function with 1 method)" | |
] | |
}, | |
"execution_count": 1, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"function self_square_a(x::Any)\n", | |
" x*x \n", | |
"end" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"self_square_n (generic function with 1 method)" | |
] | |
}, | |
"execution_count": 2, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"function self_square_n(x::Matrix{Number})\n", | |
" x*x \n", | |
"end" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"self_square_u (generic function with 1 method)" | |
] | |
}, | |
"execution_count": 3, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"function self_square_u(x::Union(Matrix{Number},Matrix{Float64}))\n", | |
" x*x\n", | |
"end" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"self_square_p (generic function with 1 method)" | |
] | |
}, | |
"execution_count": 4, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"function self_square_p{T<:Number}(x::Matrix{T})\n", | |
" x*x\n", | |
"end" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": { | |
"collapsed": false, | |
"scrolled": true | |
}, | |
"outputs": [], | |
"source": [ | |
"x500 = rand(500,500);" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"elapsed time: 0.562960516 seconds (28610856 bytes allocated, 3.89% gc time)\n", | |
"elapsed time: 0.013860367 seconds (2000160 bytes allocated)\n", | |
"elapsed time: 0.010854324 seconds (2000160 bytes allocated)\n", | |
"elapsed time: 0.010684936 seconds (2000160 bytes allocated)\n", | |
"elapsed time: 0.0099726 seconds (2000160 bytes allocated)\n" | |
] | |
} | |
], | |
"source": [ | |
"@time self_square_a(x500)\n", | |
"@time self_square_a(x500)\n", | |
"@time self_square_a(x500)\n", | |
"@time self_square_a(x500)\n", | |
"@time self_square_a(x500);" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": { | |
"collapsed": false, | |
"scrolled": true | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"elapsed time: 14.191319017 seconds (4027602028 bytes allocated, 26.06% gc time)\n", | |
"elapsed time: 15.128684707 seconds (4002000160 bytes allocated, 34.40% gc time)\n", | |
"elapsed time: 15.311365642 seconds (4002000160 bytes allocated, 34.35% gc time)\n", | |
"elapsed time: 15.481708384 seconds (4002000160 bytes allocated, 34.03% gc time)\n", | |
"elapsed time: 15.440138471 seconds (4002089504 bytes allocated, 33.99% gc time)\n" | |
] | |
} | |
], | |
"source": [ | |
"x_n500 = convert(Matrix{Number},x500)\n", | |
"@time self_square_n(x_n500)\n", | |
"@time self_square_n(x_n500)\n", | |
"@time self_square_n(x_n500)\n", | |
"@time self_square_n(x_n500)\n", | |
"@time self_square_n(x_n500);\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"elapsed time: 0.012133553 seconds (2023972 bytes allocated)\n", | |
"elapsed time: 0.009697559 seconds (2000160 bytes allocated)\n", | |
"elapsed time: 0.01103467 seconds (2000160 bytes allocated)\n", | |
"elapsed time: 0.011057954 seconds (2000160 bytes allocated)\n", | |
"elapsed time: 0.011180591 seconds (2000160 bytes allocated)\n" | |
] | |
} | |
], | |
"source": [ | |
"@time self_square_u(x500)\n", | |
"@time self_square_u(x500)\n", | |
"@time self_square_u(x500)\n", | |
"@time self_square_u(x500)\n", | |
"@time self_square_u(x500);" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"elapsed time: 0.055100636 seconds (2024484 bytes allocated)\n", | |
"elapsed time: 0.013478462 seconds (2000160 bytes allocated)\n", | |
"elapsed time: 0.009617301 seconds (2000160 bytes allocated)\n", | |
"elapsed time: 0.009809359 seconds (2000160 bytes allocated)\n", | |
"elapsed time: 0.010024266 seconds (2000160 bytes allocated)\n" | |
] | |
} | |
], | |
"source": [ | |
"@time self_square_p(x500)\n", | |
"@time self_square_p(x500)\n", | |
"@time self_square_p(x500)\n", | |
"@time self_square_p(x500)\n", | |
"@time self_square_p(x500);" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 10, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"x50 = rand(50,50);" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 11, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"elapsed time: 0.000105584 seconds (20160 bytes allocated)\n", | |
"elapsed time: 7.7349e-5 seconds (20160 bytes allocated)\n", | |
"elapsed time: 5.044e-5 seconds (20160 bytes allocated)\n", | |
"elapsed time: 4.614e-5 seconds (20160 bytes allocated)\n", | |
"elapsed time: 4.5321e-5 seconds (20160 bytes allocated)\n" | |
] | |
} | |
], | |
"source": [ | |
"@time self_square_a(x50)\n", | |
"@time self_square_a(x50)\n", | |
"@time self_square_a(x50)\n", | |
"@time self_square_a(x50)\n", | |
"@time self_square_a(x50);" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 12, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"elapsed time: 0.010720578 seconds (4020160 bytes allocated)\n", | |
"elapsed time: 0.01444303 seconds (4020160 bytes allocated)\n", | |
"elapsed time: 0.014404124 seconds (4020160 bytes allocated)\n", | |
"elapsed time: 0.013292055 seconds (4020160 bytes allocated)\n", | |
"elapsed time: 0.008447835 seconds (4020160 bytes allocated)\n" | |
] | |
} | |
], | |
"source": [ | |
"x_n50 = convert(Matrix{Number},x50)\n", | |
"@time self_square_n(x_n50)\n", | |
"@time self_square_n(x_n50)\n", | |
"@time self_square_n(x_n50)\n", | |
"@time self_square_n(x_n50)\n", | |
"@time self_square_n(x_n50);" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 13, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"elapsed time: 6.109e-5 seconds (20160 bytes allocated)\n", | |
"elapsed time: 4.8077e-5 seconds (20160 bytes allocated)\n", | |
"elapsed time: 4.5373e-5 seconds (20160 bytes allocated)\n", | |
"elapsed time: 4.6636e-5 seconds (20160 bytes allocated)\n", | |
"elapsed time: 4.5891e-5 seconds (20160 bytes allocated)\n" | |
] | |
} | |
], | |
"source": [ | |
"@time self_square_u(x50)\n", | |
"@time self_square_u(x50)\n", | |
"@time self_square_u(x50)\n", | |
"@time self_square_u(x50)\n", | |
"@time self_square_u(x50);" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 14, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"elapsed time: 4.8525e-5 seconds (20160 bytes allocated)\n", | |
"elapsed time: 4.626e-5 seconds (20160 bytes allocated)\n", | |
"elapsed time: 4.634e-5 seconds (20160 bytes allocated)\n", | |
"elapsed time: 8.593e-5 seconds (20160 bytes allocated)\n", | |
"elapsed time: 8.5882e-5 seconds (20160 bytes allocated)\n" | |
] | |
} | |
], | |
"source": [ | |
"@time self_square_p(x50)\n", | |
"@time self_square_p(x50)\n", | |
"@time self_square_p(x50)\n", | |
"@time self_square_p(x50)\n", | |
"@time self_square_p(x50);" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Julia 0.4.0-dev", | |
"language": "julia", | |
"name": "julia-0.4" | |
}, | |
"language_info": { | |
"name": "julia", | |
"version": "0.3.9" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment