def test_index_immer(benchmark): benchmark(index, push(immer.Vector()))
def test_assoc_immer(benchmark): benchmark(assoc, push(immer.Vector()))
def test_push_immer(benchmark): benchmark(push, immer.Vector())
def test_immer(self): v = immer.Vector() for i in xrange(BENCHMARK_SIZE): v = v.append(i)
import benchmark import pyrsistent import immer BENCHMARK_SIZE = 1000 BENCHMARK_RUNS = 20 def tov(v, src=xrange(BENCHMARK_SIZE)): for x in src: v = v.append(x) return v IMMER_EMPTY_VECTOR = immer.Vector() PYRSISTENT_EMPTY_VECTOR = pyrsistent.pvector() IMMER_FULL_VECTOR = tov(immer.Vector()) PYRSISTENT_FULL_VECTOR = tov(pyrsistent.pvector()) class Benchmark_Push(benchmark.Benchmark): each = BENCHMARK_RUNS def test_immer(self): v = immer.Vector() for i in xrange(BENCHMARK_SIZE): v = v.append(i) def test_pyrsistent(self):
#!/usr/bin/env python## # immer: immutable data structures for C++ # Copyright (C) 2016, 2017, 2018 Juan Pedro Bolivar Puente # # This software is distributed under the Boost Software License, Version 1.0. # See accompanying file LICENSE or copy at http://boost.org/LICENSE_1_0.txt # include:intro/start import immer v0 = immer.Vector().append(13).append(42) assert v0[0] == 13 assert v0[1] == 42 assert len(v0) == 2 v1 = v0.set(0, 12) assert v0.tolist() == [13, 42] assert v1.tolist() == [12, 42] # include:intro/end