AutoPreallocation.jl

What if your code allocated less? Remember what memory we needed last time and use it gain every time after
Author oxinabox
Popularity
38 Stars
Updated Last
7 Months Ago
Started In
February 2020

AutoPreallocation

Build Status Code Style: Blue

Have you ever wanted your code to allocate less? Have you ever felt explictly preallocating everything was just too hard? Have you ever thought: "why not just reuse the allocated memory from last time"? Well look no further, friend.

How to use:

The simplest way of using this package is via only one function preallocate, e.g

julia> using AutoPreallocation, BenchmarkTools

julia> A, B, C = (rand(1000, 1000) for _ in 1:3)
Base.Generator{UnitRange{Int64},var"#9#10"}(var"#9#10"(), 1:3)

julia> f(x, y, z) = x * y * z
f (generic function with 1 method)

julia> x, preallocated_f = preallocate(f, A, B, C);

julia> @btime f(A, B, C);
  25.684 ms (4 allocations: 15.26 MiB)

julia> @btime preallocated_f(A, B, C);
  26.077 ms (4 allocations: 144 bytes)

License

MIT License

Required Packages

Used By Packages

No packages found.