summaryrefslogtreecommitdiff
path: root/examples/performance.py
blob: ec6c830d31b70ffa4a7b973331ecf3dd9d435447 (plain)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""
Compute distances of large sets of spike trains for performance tests

Copyright 2015, Mario Mulansky <mario.mulansky@gmx.net>

Distributed under the BSD License

"""

from __future__ import print_function

import pyspike as spk
from datetime import datetime
import cProfile
import pstats

# in case you dont have the cython backends, disable the warnings as follows:
# spk.disable_backend_warning = True

M = 100    # number of spike trains
r = 1.0    # rate of Poisson spike times
T = 1E3    # length of spike trains

print("%d spike trains with %d spikes" % (M, int(r*T)))

spike_trains = []

t_start = datetime.now()
for i in range(M):
    spike_trains.append(spk.generate_poisson_spikes(r, T))
t_end = datetime.now()
runtime = (t_end-t_start).total_seconds()

print("Spike generation runtime: %.3fs" % runtime)
print()

print("================ ISI COMPUTATIONS ================")
print("    MULTIVARIATE DISTANCE")
cProfile.run('spk.isi_distance_multi(spike_trains)', 'performance.stat')
p = pstats.Stats('performance.stat')
p.strip_dirs().sort_stats('tottime').print_stats(5)

print("    MULTIVARIATE PROFILE")
cProfile.run('spk.isi_profile_multi(spike_trains)', 'performance.stat')
p = pstats.Stats('performance.stat')
p.strip_dirs().sort_stats('tottime').print_stats(5)

print("================ SPIKE COMPUTATIONS ================")
print("    MULTIVARIATE DISTANCE")
cProfile.run('spk.spike_distance_multi(spike_trains)', 'performance.stat')
p = pstats.Stats('performance.stat')
p.strip_dirs().sort_stats('tottime').print_stats(5)

print("    MULTIVARIATE PROFILE")
cProfile.run('spk.spike_profile_multi(spike_trains)', 'performance.stat')
p = pstats.Stats('performance.stat')
p.strip_dirs().sort_stats('tottime').print_stats(5)

print("================ SPIKE-SYNC COMPUTATIONS ================")
print("    MULTIVARIATE DISTANCE")
cProfile.run('spk.spike_sync_multi(spike_trains)', 'performance.stat')
p = pstats.Stats('performance.stat')
p.strip_dirs().sort_stats('tottime').print_stats(5)

print("    MULTIVARIATE PROFILE")
cProfile.run('spk.spike_sync_profile_multi(spike_trains)', 'performance.stat')
p = pstats.Stats('performance.stat')
p.strip_dirs().sort_stats('tottime').print_stats(5)