コード例 #1
0
ファイル: HashTable.py プロジェクト: ya-mouse/pyshmht
 def __getitem__(self, key):
     val = shmht.getval(self.fd, key)
     if val == None:
         raise KeyError(key)
     return val
コード例 #2
0
ファイル: HashTable.py プロジェクト: ya-mouse/pyshmht
 def __contains__(self, key):
     return shmht.getval(self.fd, key) != None
コード例 #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)
コード例 #4
0
ファイル: HashTable.py プロジェクト: ya-mouse/pyshmht
 def get(self, key, default=None):
     val = shmht.getval(self.fd, key)
     if val == None:
         return default
     return val
コード例 #5
0
ファイル: trivial.py プロジェクト: vglaidler/ext_shmht
        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)
コード例 #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)
コード例 #7
0
 def __contains__(self, key):
     return shmht.getval(self.fd, key) != None
コード例 #8
0
 def __getitem__(self, key):
     val = shmht.getval(self.fd, key)
     if val == None:
         raise KeyError(key)
     return val
コード例 #9
0
 def get(self, key, default=None):
     val = shmht.getval(self.fd, key)
     if val == None:
         return default
     return val