Skip to content

New version for reducing memory consumption #387

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions bench/ndarray/array-constructor-memray.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#######################################################################
# Copyright (c) 2019-present, Blosc Development Team <[email protected]>
# All rights reserved.
#
# This source code is licensed under a BSD-style license (found in the
# LICENSE file in the root directory of this source tree)
#######################################################################

from time import time
import os

import numpy as np
import memray

import blosc2

N = 100_000_000


def info(a, t1):
size = a.schunk.nbytes
csize = a.schunk.cbytes
print(
f"Time: {t1:.3f} s - size: {size / 2 ** 30:.2f} GB ({size / t1 / 2 ** 30:.2f} GB/s)"
f"\tStorage required: {csize / 2 ** 20:.2f} MB (cratio: {size / csize:.1f}x)"
)


def run_benchmark():
shape = (N,)
shape = (100, 1000, 1000)
print(f"*** Creating a blosc2 array with {N:_} elements (shape: {shape}) ***")
t0 = time()
#a = blosc2.arange(N, shape=shape, dtype=np.int32, urlpath="a.b2nd", mode="w")
a = blosc2.linspace(0, 1, N, shape=shape, dtype=np.float64, urlpath="a.b2nd", mode="w")
elapsed = time() - t0
info(a, elapsed)
return a


# Check if we're being tracked by memray
if not os.environ.get("MEMRAY_TRACKING", False):
# Run the benchmark with memray tracking
output_file = "array_constructor_memray.bin"
print(f"Starting memray profiling. Results will be saved to {output_file}")

with memray.Tracker(output_file):
array = run_benchmark()

print(f"\nMemray profiling completed. To view results, run:")
print(f"memray flamegraph {output_file}")
print(f"# or")
print(f"memray summary {output_file}")
print(f"# or")
print(f"memray tree {output_file}")
else:
# We're already being tracked by memray
run_benchmark()
32 changes: 32 additions & 0 deletions bench/ndarray/array-constructor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#######################################################################
# Copyright (c) 2019-present, Blosc Development Team <[email protected]>
# All rights reserved.
#
# This source code is licensed under a BSD-style license (found in the
# LICENSE file in the root directory of this source tree)
#######################################################################

from time import time

import numpy as np

import blosc2

N = 100_000_000

def info(a, t1):
size = a.schunk.nbytes
csize = a.schunk.cbytes
print(
f"Time: {t1:.3f} s - size: {size / 2 ** 30:.2f} GB ({size / t1 / 2 ** 30:.2f} GB/s)"
f"\tStorage required: {csize / 2 ** 20:.2f} MB (cratio: {size / csize:.1f}x)"
)


shape = (N,)
shape = (100, 1000, 1000)
print(f"*** Creating a blosc2 array with {N:_} elements (shape: {shape}) ***")
t0 = time()
# a = blosc2.arange(N, shape=shape, dtype=np.int32, urlpath="a.b2nd", mode="w")
a = blosc2.linspace(0, 1, N, shape=shape, dtype=np.float64, urlpath="a.b2nd", mode="w")
info(a, time() - t0)
Loading