Skip to content

adding a small integer to a BigInt with operate! allocates #353

@nsajko

Description

@nsajko

Presumably the small integer is being converted to BigInt by mistake. It is possible to add some small ints to a BigInt directly using Base.GMP.MPZ.add_si! (or Base.GMP.MPZ.add_ui!).

julia> using MutableArithmetics: MutableArithmetics as MA

julia> x = BigInt(0)
0

julia> @timev MA.operate!(+, x, 1)
  0.086091 seconds (135.80 k allocations: 7.078 MiB, 99.88% compilation time)
elapsed time (ns):  8.6090543e7
gc time (ns):       0
bytes allocated:    7421600
pool allocs:        135768
non-pool GC allocs: 1
malloc() calls:     34
realloc() calls:    1
free() calls:       0
minor collections:  0
full collections:   0
1

julia> @timev MA.operate!(+, x, 1)
  0.000022 seconds (2 allocations: 56 bytes)
elapsed time (ns):  21772.0
gc time (ns):       0
bytes allocated:    56
pool allocs:        1
non-pool GC allocs: 0
malloc() calls:     1
free() calls:       0
minor collections:  0
full collections:   0
2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions