NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

benchmark_indexes.py (2775B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\fsd\schemas\benchmarks\benchmark_indexes.py
      2 from __future__ import print_function
      3 import pyFSD
      4 import time
      5 import ctypes
      6 import cPickle
      7 import marshal
      8 import fsd.schemas.validator as validator
      9 import fsd.schemas.schemaOptimizer as schemaOptimizer
     10 import fsd.schemas.binaryRepresenter as binaryRepresenter
     11 import fsd.schemas.binaryLoader as binaryLoader
     12 import fsd.schemas.loaders.dictLoader as dictLoader
     13 schema = {'type': 'dict',
     14  'buildIndex': True,
     15  'keyTypes': {'type': 'int',
     16               'min': 0},
     17  'valueTypes': {'type': 'int'}}
     18 optSchema = schemaOptimizer.OptimizeSchema(schema, validator.SERVER)
     19 keySchema = optSchema['keyFooter']
     20 
     21 def timeit(method):
     22 
     23     def timed(*args, **kw):
     24         ts = time.time()
     25         result = method(*args, **kw)
     26         te = time.time()
     27         print('%r (%r, %r) %2.2f sec' % (method.__name__,
     28          args,
     29          kw,
     30          te - ts))
     31         return result
     32 
     33     return timed
     34 
     35 
     36 offsets = []
     37 COUNT = 500000
     38 for i in xrange(COUNT):
     39     offsets.append({'key': i,
     40      'offset': 0,
     41      'size': 0})
     42 
     43 offsetTableString = binaryRepresenter.RepresentAsBinary(offsets, keySchema, None)
     44 print('Timing %i item indexes' % COUNT)
     45 
     46 @timeit
     47 def FsdUnsignedIntegerKeyMapLoadData():
     48     keyMap = pyFSD.FsdUnsignedIntegerKeyMap()
     49     keyMap.Initialize(offsetTableString)
     50     return dictLoader.CppFsdIntegerKeyMapWrapper(keyMap)
     51 
     52 
     53 @timeit
     54 def PythonFSDKeyMapLoadData():
     55     buff = ctypes.create_string_buffer(offsetTableString, len(offsetTableString))
     56     return dictLoader.StandardFSDDictFooter(buff, 0, keySchema, None, binaryLoader.LoaderState(binaryLoader.defaultLoaderFactories, None))
     57 
     58 
     59 cppLookup = FsdUnsignedIntegerKeyMapLoadData()
     60 
     61 @timeit
     62 def FsdUnsignedIntegerKeyMapAccessAllElements():
     63     for i in xrange(COUNT):
     64         cppLookup.Get(i)
     65 
     66 
     67 @timeit
     68 def FsdUnsignedIntegerKeyMapAccessAllElementsWithoutAttrLookup():
     69     Get = cppLookup.Get
     70     for i in xrange(COUNT):
     71         Get(i)
     72 
     73 
     74 FsdUnsignedIntegerKeyMapAccessAllElements()
     75 FsdUnsignedIntegerKeyMapAccessAllElementsWithoutAttrLookup()
     76 
     77 @timeit
     78 def PythonFSDDataAccessAllElements():
     79     for i in xrange(COUNT):
     80         pythonLookup.Get(i)
     81 
     82 
     83 dataAsDict = {}
     84 for i in xrange(COUNT):
     85     dataAsDict[i] = (0, 0)
     86 
     87 pickledData = cPickle.dumps(dataAsDict, protocol=cPickle.HIGHEST_PROTOCOL)
     88 
     89 @timeit
     90 def PythonDictLoadFromCPickle():
     91     return cPickle.loads(pickledData)
     92 
     93 
     94 dataAsDict = PythonDictLoadFromCPickle()
     95 marshalledData = marshal.dumps(dataAsDict)
     96 
     97 @timeit
     98 def PythonDictLoadFromMarshall():
     99     return marshal.loads(marshalledData)
    100 
    101 
    102 PythonDictLoadFromMarshall()
    103 
    104 @timeit
    105 def PythonDictAccessAllElements():
    106     for i in xrange(COUNT):
    107         dataAsDict.get(i)
    108 
    109 
    110 PythonDictAccessAllElements()