summaryrefslogtreecommitdiffstats
path: root/src/arrow/python/benchmarks/plasma.py
blob: 90a284515315c36cdb29de3973145f0d9b3232ae (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
69
70
71
72
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

import numpy as np
import timeit

try:
    import pyarrow.plasma as plasma
except ImportError:
    # TODO(wesm): These are not asv benchmarks, so we can just fail
    # silently here
    pass


class SimplePlasmaThroughput(object):
    """Benchmark plasma store throughput with a single client."""

    params = [1000, 100000, 10000000]

    timer = timeit.default_timer

    def setup(self, size):
        self.plasma_store_ctx = plasma.start_plasma_store(
            plasma_store_memory=10**9)
        plasma_store_name, p = self.plasma_store_ctx.__enter__()
        self.plasma_client = plasma.connect(plasma_store_name)

        self.data = np.random.randn(size // 8)

    def teardown(self, size):
        self.plasma_store_ctx.__exit__(None, None, None)

    def time_plasma_put_data(self, size):
        self.plasma_client.put(self.data)


class SimplePlasmaLatency(object):
    """Benchmark plasma store latency with a single client."""

    timer = timeit.default_timer

    def setup(self):
        self.plasma_store_ctx = plasma.start_plasma_store(
            plasma_store_memory=10**9)
        plasma_store_name, p = self.plasma_store_ctx.__enter__()
        self.plasma_client = plasma.connect(plasma_store_name)

    def teardown(self):
        self.plasma_store_ctx.__exit__(None, None, None)

    def time_plasma_put(self):
        for i in range(1000):
            self.plasma_client.put(1)

    def time_plasma_putget(self):
        for i in range(1000):
            x = self.plasma_client.put(1)
            self.plasma_client.get(x)