documentation or quick demo?
Closed this issue · 3 comments
Moelf commented
Definitely helps attract eyeballs and help people decide if this is the package they're looking for.
carstenbauer commented
Maybe it's useful to start collecting some basic examples. Here's a serve:
Float64 vs Int64
Code
julia> about(3.123)
Float64 (<: AbstractFloat <: Real <: Number <: Any), occupies 8B.
0100000000001000111110111110011101101100100010110100001110010110
╨└────┬────┘└────────────────────────┬─────────────────────────┘
+ 2^1 × 1.561500000000000110
= 3.1230000000000002
julia> about(5) # Int64
Int64 (<: Signed <: Integer <: Real <: Number <: Any), occupies 8B.
0000000000000000000000000000000000000000000000000000000000000101
= +5
julia> about(-5) # Int64
Int64 (<: Signed <: Integer <: Real <: Number <: Any), occupies 8B.
1111111111111111111111111111111111111111111111111111111111111011
= -5
Vector vs Tuple
Code
julia> a = 1.234; b = 5.678;
julia> tuple = (a,b);
julia> vector = [a,b];
julia> about(vector)
2-element Vector{Float64} (mutable) (<: DenseVector{Float64} <: AbstractVector{Float64} <: Any)
Memory footprint: 24B directly (referencing 72B in total, holding 16B of data)
ref::MemoryRef{Float64} 16B «struct» MemoryRef{Float64}(Ptr{Nothing}(0x000000010a008cb0), [1.234, 5.678])
size::Tuple{Int64} 8B «struct» (2,)
■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
16B 8B
julia> about(tuple)
Tuple{Float64, Float64} (<: Any), occupies 16B.
1::Float64 8B 001111111111001110111110011101 … 01000101101000011100101011000 1.234
2::Float64 8B 010000000001011010110110010001 … 00001110010101100000010000011 5.678
■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
8B 8B
View
Code
julia> about(@view rand(5,5)[:,1])
5-element view(::Matrix{Float64}, :, 1) with eltype Float64 (<: AbstractVector{Float64} <: Any)
Memory footprint: 40B directly (referencing 304B in total)
parent::Matrix{Float64} 8B @ 0x000000017a7608e0 [0.662379 0.19 … 8305 0.162217]
indices::Tuple{Base.Slice{Base.OneTo{Int64… 16B «struct» (Base.Slice(Base.OneTo(5)), 1)
offset1::Int64 8B 00000000000000000000000000000 … 0000000000000000000000000000 0
stride1::Int64 8B 00000000000000000000000000000 … 0000000000000000000000000001 1
■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
* 16B 8B 8B
* = Pointer (8B)
Heterogeneous named tuples
Code
julia> about((; a=1, b=2.34, c=0x12, d="hello"))
@NamedTuple{a::Int64, b::Float64, c::UInt8, d::String} (<: Any), occupies 32B directly (referencing 45B in total)
a::Int64 8B 0000000000000000000000000000000000000000000000000000000000000001 1
b::Float64 8B 0100000000000010101110000101000111101011100001010001111010111000 2.34
c::UInt8 8B 00010010 0x12
d::String 8B @ 0x000000017ad6cd00 "hello"
■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
8B 8B 1B+7B *
* = Pointer (8B)
Inspecting Dict
Code
julia> about(Dict)
UnionAll defined in Base,
Dict{K, V} <: AbstractDict{K, V} <: Any
Struct with 8 fields:
• slots::Memory{UInt8}
• keys::Memory
• vals::Memory
• ndel::Int64
• count::Int64
• age::UInt64
• idxfloor::Int64
• maxprobe::Int64
julia> about(Dict(1 => "a", 2 => 'b'))
Dict{Int64, Any} with 2 entries (mutable) (<: AbstractDict{Int64, Any} <: Any), occupies 64B directly (referencing 397B in total)
slots::Memory{UInt8} 8B @ 0x000000017a0284d0 UInt8[0x00, 0x00, 0x00, … x00, 0x00, 0xad, 0x00]
keys::Memory{Int64} 8B @ 0x0000000177f991a0 [4725441632, 4460318864 … , 0, 0, 0, 0, 0, 1, 0]
vals::Memory{Any} 8B @ 0x0000000177ef8020 Any[#undef, #undef, #un … , #undef, "a", #undef]
ndel::Int64 8B 0000000000000000000000000000000000000000000000000000000000000000 0
count::Int64 8B 0000000000000000000000000000000000000000000000000000000000000010 2
age::UInt64 8B 0000000000000000000000000000000000000000000000000000000000000011 0x0000000000000003
idxfloor::Int64 8B 0000000000000000000000000000000000000000000000000000000000000001 1
maxprobe::Int64 8B 0000000000000000000000000000000000000000000000000000000000000000 0
■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
* * * 8B 8B 8B 8B 8B
* = Pointer (8B)
Effects
Code
julia> about(sum, Vector{Float64})
sum (generic function with 13 methods)
Defined in Base(8) extended in StaticArrays(3), Base.MPFR(1), and Base.GMP(1).
Matched 1 method :: Float64
sum(a::AbstractArray; dims, kw...) @ Base reducedim.jl:980
Method effects:
✗ consistent might not return or terminate consistently
✗ effect free might not be free from externally semantically visible side effects
✔ no throw guaranteed to never throw an exception
✔ terminates guaranteed to always terminate
✔ no task state guaranteed not to access task state (allowing migration between tasks)
✗ inaccessible memory only may access or modify externally accessible mutable memory
✗ no undefined behaviour may execute undefined behaviour
✔ non-overlayed may call methods from an overlayed method table
julia> about(sum, SVector{2, Float64})
sum (generic function with 13 methods)
Defined in Base(8) extended in StaticArrays(3), Base.MPFR(1), and Base.GMP(1).
Matched 1 method :: Float64
sum(a::StaticArray{<:Tuple, T}; dims) where T @ StaticArrays ~/.julia/packages/StaticArrays/YN0oL/src/mapreduce.jl:285
Method effects:
✔ consistent guaranteed to return or terminate consistently
✔ effect free guaranteed to be free from externally semantically visible side effects
✔ no throw may throw an exception
✔ terminates might not always terminate
✔ no task state may access task state (preventing migration between tasks)
✔ inaccessible memory only guaranteed to never access or modify externally accessible mutable memory
✔ no undefined behaviour guaranteed to never execute undefined behaviour
✔ non-overlayed never calls any methods from an overlayed method table
tecosaur commented
I've added some plaintext examples to the readme. It's not quite as pretty as these screenshots, but it won't inflate the git repository as much as images 🙂.
tecosaur commented
I think that's good enough for now 🙂