File: profile_points.py

package info (click to toggle)
napari 0.6.6-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 12,036 kB
  • sloc: python: 112,264; xml: 72; makefile: 44; sh: 5
file content (35 lines) | stat: -rw-r--r-- 653 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import cProfile
import io
import pstats
from pstats import SortKey

import numpy as np

from napari.layers import Points

"""
This script was useful for testing how the performance of
Points._set_view_slice changed with different implementations during async
development.
"""

np.random.seed(0)

n = 65536
data = np.random.random((n, 2))
s = io.StringIO()

reps = 100

# Profiling
with cProfile.Profile() as pr:
    for _ in range(reps):
        layer = Points(data)
        layer._set_view_slice()

sortby = SortKey.CUMULATIVE
ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
ps.print_stats(0.05)
print(s.getvalue())

# pr.dump_stats("result.pstat")