3 ms·
Raw speed. Although julia has several nice features (multiple dynamic dispatch, macros), the raw speed obtained by annotating code with types is mind blowing. Y
by enitihas 8y ago
Raw speed. Although julia has several nice features (multiple dynamic dispatch, macros), the raw speed obtained by annotating code with types is mind blowing. You can for the most part write like python, then annotate the slowest parts with types. It works really well.
- ChrisRackauckas 8y agoYou don't need to annotate types to get the speed.
- stabbles 8y agoYou don't even need to annotate things with types! > square(x) = x * x > @code_typed square(2.0) CodeInfo( 1 1 ─ %1 = Base.mul_float(%%x, %%x)::Float64 └── return %1 ) => Float64 > @code_typed square(2) CodeInfo( 1 1 ─ %1 = Base.mul_int(%%x, %%x)::Int64 └── return %1 ) => Int64 Functions specialize automatically to the arguments you pass in.
- ChrisFoster 8y agoOr, to see what's really going on at a low level you have immediate access to the native assembly from the REPL: julia> square(x) = x^2 square (generic function with 1 method) julia> @code_native square(1) .text Filename: REPL[3] pushq %rbp movq %rsp, %rbp Source line: 1 imulq %rdi, %rdi movq %rdi, %rax popq %rbp retq julia> @code_native square(1.0) .text Filename: REPL[3] pushq %rbp movq %rsp, %rbp Source line: 1 mulsd %xmm0, %xmm0 popq %rbp retq
- DNF2 8y agoYou don't need to annotate function definitions with types, but you should actually annotate your composite type definitions with concrete (parametric) types for each field.
- oxinabox 8y agoSyntax, semantics (multiple dispatch, type system), and community (so many clever people working together sharing expertise)