Ejemplo n.º 1
0
 def __getitem__(self, key):
     val = shmht.getval(self.fd, key)
     if val == None:
         raise KeyError(key)
     return val
Ejemplo n.º 2
0
 def __contains__(self, key):
     return shmht.getval(self.fd, key) != None
Ejemplo n.º 3
0
#!/usr/bin/python
#coding: utf-8

import shmht
import time

capacity = 300000

fd = shmht.open('/dev/shm/test.performance', capacity, 1)

begin_time = time.time()
for i in range(capacity):
    s = '%064d' % i
    shmht.setval(fd, s, s)
end_time = time.time()
print(capacity / (end_time - begin_time), 'iops @ set')

begin_timend_time = time.time()
for i in range(capacity):
    s = '%064d' % i
    if s != shmht.getval(fd, s):
        raise Exception(s)
end_time = time.time()
print(capacity / (end_time - begin_time), 'iops @ get')

shmht.close(fd)
Ejemplo n.º 4
0
 def get(self, key, default=None):
     val = shmht.getval(self.fd, key)
     if val == None:
         return default
     return val
Ejemplo n.º 5
0
        ident = shmht.open(testfile)

    except shmht.error as e:
        pass

    else:
        assert False, 'should have raised an exception'

with pycode.test('open-init'):

    ident = shmht.open(testfile, 10)

with pycode.test('insert-lookup'):

    shmht.setval(ident, 'arf', 'data for arf')
    assert shmht.getval(ident, 'arf') == 'data for arf'

    shmht.setval(ident, 'narf', 'data for narf')
    assert shmht.getval(ident, 'narf') == 'data for narf'

    assert shmht.getval(ident, 'arf') == 'data for arf'
    assert shmht.getval(ident, 'narf') == 'data for narf'

with pycode.test('iter-small'):
    d = {}

    def collect(key, value):
        d[key] = value

    shmht.foreach(ident, collect)
Ejemplo n.º 6
0
#!/usr/bin/python
#coding: utf-8

import shmht
import time

capacity = 300000

fd = shmht.open('/dev/shm/test.performance', capacity, 1)

begin_time = time.time()
for i in range(capacity):
    s = bytes('%064d' % i, 'ascii')
    shmht.setval(fd, s, s)
end_time = time.time()
print(capacity / (end_time - begin_time), 'iops @ set')

begin_timend_time = time.time()
for i in range(capacity):
    s = bytes('%064d' % i, 'ascii')
    if s != shmht.getval(fd, s):
        raise Exception(s)
end_time = time.time()
print(capacity / (end_time - begin_time), 'iops @ get')

shmht.close(fd)
Ejemplo n.º 7
0
 def __contains__(self, key):
     return shmht.getval(self.fd, key) != None
Ejemplo n.º 8
0
 def __getitem__(self, key):
     val = shmht.getval(self.fd, key)
     if val == None:
         raise KeyError(key)
     return val
Ejemplo n.º 9
0
 def get(self, key, default=None):
     val = shmht.getval(self.fd, key)
     if val == None:
         return default
     return val