Applying black formatting
- Fixing flake8 configuration to agree with black - Adding black validation check to github actions
This commit is contained in:
@@ -2,50 +2,50 @@ import os
|
||||
import capnp
|
||||
|
||||
this_dir = os.path.dirname(__file__)
|
||||
addressbook = capnp.load(os.path.join(this_dir, 'addressbook.capnp'))
|
||||
addressbook = capnp.load(os.path.join(this_dir, "addressbook.capnp"))
|
||||
|
||||
print = lambda *x: x
|
||||
|
||||
|
||||
def writeAddressBook():
|
||||
addressBook = addressbook.AddressBook.new_message()
|
||||
people = addressBook.init_resizable_list('people')
|
||||
people = addressBook.init_resizable_list("people")
|
||||
|
||||
alice = people.add()
|
||||
alice.id = 123
|
||||
alice.name = 'Alice'
|
||||
alice.email = 'alice@example.com'
|
||||
alicePhones = alice.init('phones', 1)
|
||||
alice.name = "Alice"
|
||||
alice.email = "alice@example.com"
|
||||
alicePhones = alice.init("phones", 1)
|
||||
alicePhones[0].number = "555-1212"
|
||||
alicePhones[0].type = 'mobile'
|
||||
alicePhones[0].type = "mobile"
|
||||
|
||||
bob = people.add()
|
||||
bob.id = 456
|
||||
bob.name = 'Bob'
|
||||
bob.email = 'bob@example.com'
|
||||
bobPhones = bob.init('phones', 2)
|
||||
bob.name = "Bob"
|
||||
bob.email = "bob@example.com"
|
||||
bobPhones = bob.init("phones", 2)
|
||||
bobPhones[0].number = "555-4567"
|
||||
bobPhones[0].type = 'home'
|
||||
bobPhones[0].type = "home"
|
||||
bobPhones[1].number = "555-7654"
|
||||
bobPhones[1].type = 'work'
|
||||
bobPhones[1].type = "work"
|
||||
|
||||
people.finish()
|
||||
msg_bytes = addressBook.to_bytes()
|
||||
return msg_bytes
|
||||
|
||||
|
||||
def printAddressBook(msg_bytes):
|
||||
addressBook = addressbook.AddressBook.from_bytes(msg_bytes)
|
||||
|
||||
for person in addressBook.people:
|
||||
print(person.name, ':', person.email)
|
||||
print(person.name, ":", person.email)
|
||||
for phone in person.phones:
|
||||
print(phone.type, ':', phone.number)
|
||||
print(phone.type, ":", phone.number)
|
||||
print()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
for i in range(10000):
|
||||
msg_bytes = writeAddressBook()
|
||||
|
||||
printAddressBook(msg_bytes)
|
||||
|
||||
|
||||
@@ -6,35 +6,38 @@ try:
|
||||
except:
|
||||
profile = lambda func: func
|
||||
this_dir = os.path.dirname(__file__)
|
||||
addressbook = capnp.load(os.path.join(this_dir, 'addressbook.capnp'))
|
||||
addressbook = capnp.load(os.path.join(this_dir, "addressbook.capnp"))
|
||||
|
||||
print = lambda *x: x
|
||||
|
||||
|
||||
@profile
|
||||
def writeAddressBook():
|
||||
addressBook = addressbook.AddressBook.new_message()
|
||||
people = addressBook.init('people', 2)
|
||||
people = addressBook.init("people", 2)
|
||||
|
||||
alice = people[0]
|
||||
alice.id = 123
|
||||
alice.name = 'Alice'
|
||||
alice.email = 'alice@example.com'
|
||||
alicePhones = alice.init('phones', 1)
|
||||
alice.name = "Alice"
|
||||
alice.email = "alice@example.com"
|
||||
alicePhones = alice.init("phones", 1)
|
||||
alicePhones[0].number = "555-1212"
|
||||
alicePhones[0].type = 'mobile'
|
||||
alicePhones[0].type = "mobile"
|
||||
|
||||
bob = people[1]
|
||||
bob.id = 456
|
||||
bob.name = 'Bob'
|
||||
bob.email = 'bob@example.com'
|
||||
bobPhones = bob.init('phones', 2)
|
||||
bob.name = "Bob"
|
||||
bob.email = "bob@example.com"
|
||||
bobPhones = bob.init("phones", 2)
|
||||
bobPhones[0].number = "555-4567"
|
||||
bobPhones[0].type = 'home'
|
||||
bobPhones[0].type = "home"
|
||||
bobPhones[1].number = "555-7654"
|
||||
bobPhones[1].type = 'work'
|
||||
bobPhones[1].type = "work"
|
||||
|
||||
msg_bytes = addressBook.to_bytes()
|
||||
return msg_bytes
|
||||
|
||||
|
||||
@profile
|
||||
def printAddressBook(msg_bytes):
|
||||
addressBook = addressbook.AddressBook.from_bytes(msg_bytes)
|
||||
@@ -44,31 +47,34 @@ def printAddressBook(msg_bytes):
|
||||
for phone in person.phones:
|
||||
phone.type, phone.number
|
||||
|
||||
|
||||
@profile
|
||||
def writeAddressBookDict():
|
||||
addressBook = addressbook.AddressBook.new_message()
|
||||
people = addressBook.init('people', 2)
|
||||
people = addressBook.init("people", 2)
|
||||
|
||||
alice = people[0]
|
||||
alice.id = 123
|
||||
alice.name = 'Alice'
|
||||
alice.email = 'alice@example.com'
|
||||
alicePhones = alice.init('phones', 1)
|
||||
alice.name = "Alice"
|
||||
alice.email = "alice@example.com"
|
||||
alicePhones = alice.init("phones", 1)
|
||||
alicePhones[0].number = "555-1212"
|
||||
alicePhones[0].type = 'mobile'
|
||||
alicePhones[0].type = "mobile"
|
||||
|
||||
bob = people[1]
|
||||
bob.id = 456
|
||||
bob.name = 'Bob'
|
||||
bob.email = 'bob@example.com'
|
||||
bobPhones = bob.init('phones', 2)
|
||||
bob.name = "Bob"
|
||||
bob.email = "bob@example.com"
|
||||
bobPhones = bob.init("phones", 2)
|
||||
bobPhones[0].number = "555-4567"
|
||||
bobPhones[0].type = 'home'
|
||||
bobPhones[0].type = "home"
|
||||
bobPhones[1].number = "555-7654"
|
||||
bobPhones[1].type = 'work'
|
||||
bobPhones[1].type = "work"
|
||||
|
||||
msg = addressBook.to_dict()
|
||||
return msg
|
||||
|
||||
|
||||
@profile
|
||||
def printAddressBookDict(msg):
|
||||
addressBook = addressbook.AddressBook.new_message(**msg)
|
||||
@@ -79,7 +85,7 @@ def printAddressBookDict(msg):
|
||||
phone.type, phone.number
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
# for i in range(10000):
|
||||
# msg_bytes = writeAddressBook()
|
||||
|
||||
@@ -88,4 +94,3 @@ if __name__ == '__main__':
|
||||
msg = writeAddressBookDict()
|
||||
|
||||
printAddressBookDict(msg)
|
||||
|
||||
|
||||
@@ -9,16 +9,16 @@ def writeAddressBook():
|
||||
|
||||
alice = addressBook.person.add()
|
||||
alice.id = 123
|
||||
alice.name = 'Alice'
|
||||
alice.email = 'alice@example.com'
|
||||
alice.name = "Alice"
|
||||
alice.email = "alice@example.com"
|
||||
alicePhones = [alice.phone.add()]
|
||||
alicePhones[0].number = "555-1212"
|
||||
alicePhones[0].type = addressbook.Person.MOBILE
|
||||
|
||||
bob = addressBook.person.add()
|
||||
bob.id = 456
|
||||
bob.name = 'Bob'
|
||||
bob.email = 'bob@example.com'
|
||||
bob.name = "Bob"
|
||||
bob.email = "bob@example.com"
|
||||
bobPhones = [bob.phone.add(), bob.phone.add()]
|
||||
bobPhones[0].number = "555-4567"
|
||||
bobPhones[0].type = addressbook.Person.HOME
|
||||
@@ -34,15 +34,14 @@ def printAddressBook(message_string):
|
||||
addressBook.ParseFromString(message_string)
|
||||
|
||||
for person in addressBook.person:
|
||||
print(person.name, ':', person.email)
|
||||
print(person.name, ":", person.email)
|
||||
for phone in person.phone:
|
||||
print(phone.type, ':', phone.number)
|
||||
print(phone.type, ":", phone.number)
|
||||
print()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
for i in range(10000):
|
||||
message_string = writeAddressBook()
|
||||
|
||||
printAddressBook(message_string)
|
||||
|
||||
|
||||
@@ -2,204 +2,276 @@
|
||||
# source: addressbook.proto
|
||||
|
||||
import sys
|
||||
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
|
||||
|
||||
_b = sys.version_info[0] < 3 and (lambda x: x) or (lambda x: x.encode("latin1"))
|
||||
from google.protobuf import descriptor as _descriptor
|
||||
from google.protobuf import message as _message
|
||||
from google.protobuf import reflection as _reflection
|
||||
from google.protobuf import symbol_database as _symbol_database
|
||||
from google.protobuf import descriptor_pb2
|
||||
|
||||
# @@protoc_insertion_point(imports)
|
||||
|
||||
_sym_db = _symbol_database.Default()
|
||||
|
||||
|
||||
|
||||
|
||||
DESCRIPTOR = _descriptor.FileDescriptor(
|
||||
name='addressbook.proto',
|
||||
package='tutorial',
|
||||
syntax='proto2',
|
||||
serialized_pb=_b('\n\x11\x61\x64\x64ressbook.proto\x12\x08tutorial\"\xda\x01\n\x06Person\x12\x0c\n\x04name\x18\x01 \x02(\t\x12\n\n\x02id\x18\x02 \x02(\x05\x12\r\n\x05\x65mail\x18\x03 \x02(\t\x12+\n\x05phone\x18\x04 \x03(\x0b\x32\x1c.tutorial.Person.PhoneNumber\x1aM\n\x0bPhoneNumber\x12\x0e\n\x06number\x18\x01 \x02(\t\x12.\n\x04type\x18\x02 \x01(\x0e\x32\x1a.tutorial.Person.PhoneType:\x04HOME\"+\n\tPhoneType\x12\n\n\x06MOBILE\x10\x00\x12\x08\n\x04HOME\x10\x01\x12\x08\n\x04WORK\x10\x02\"/\n\x0b\x41\x64\x64ressBook\x12 \n\x06person\x18\x01 \x03(\x0b\x32\x10.tutorial.Person')
|
||||
name="addressbook.proto",
|
||||
package="tutorial",
|
||||
syntax="proto2",
|
||||
serialized_pb=_b(
|
||||
'\n\x11\x61\x64\x64ressbook.proto\x12\x08tutorial"\xda\x01\n\x06Person\x12\x0c\n\x04name\x18\x01 \x02(\t\x12\n\n\x02id\x18\x02 \x02(\x05\x12\r\n\x05\x65mail\x18\x03 \x02(\t\x12+\n\x05phone\x18\x04 \x03(\x0b\x32\x1c.tutorial.Person.PhoneNumber\x1aM\n\x0bPhoneNumber\x12\x0e\n\x06number\x18\x01 \x02(\t\x12.\n\x04type\x18\x02 \x01(\x0e\x32\x1a.tutorial.Person.PhoneType:\x04HOME"+\n\tPhoneType\x12\n\n\x06MOBILE\x10\x00\x12\x08\n\x04HOME\x10\x01\x12\x08\n\x04WORK\x10\x02"/\n\x0b\x41\x64\x64ressBook\x12 \n\x06person\x18\x01 \x03(\x0b\x32\x10.tutorial.Person'
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
|
||||
_PERSON_PHONETYPE = _descriptor.EnumDescriptor(
|
||||
name='PhoneType',
|
||||
full_name='tutorial.Person.PhoneType',
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
values=[
|
||||
_descriptor.EnumValueDescriptor(
|
||||
name='MOBILE', index=0, number=0,
|
||||
options=None,
|
||||
type=None),
|
||||
_descriptor.EnumValueDescriptor(
|
||||
name='HOME', index=1, number=1,
|
||||
options=None,
|
||||
type=None),
|
||||
_descriptor.EnumValueDescriptor(
|
||||
name='WORK', index=2, number=2,
|
||||
options=None,
|
||||
type=None),
|
||||
],
|
||||
containing_type=None,
|
||||
options=None,
|
||||
serialized_start=207,
|
||||
serialized_end=250,
|
||||
name="PhoneType",
|
||||
full_name="tutorial.Person.PhoneType",
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
values=[
|
||||
_descriptor.EnumValueDescriptor(
|
||||
name="MOBILE", index=0, number=0, options=None, type=None
|
||||
),
|
||||
_descriptor.EnumValueDescriptor(
|
||||
name="HOME", index=1, number=1, options=None, type=None
|
||||
),
|
||||
_descriptor.EnumValueDescriptor(
|
||||
name="WORK", index=2, number=2, options=None, type=None
|
||||
),
|
||||
],
|
||||
containing_type=None,
|
||||
options=None,
|
||||
serialized_start=207,
|
||||
serialized_end=250,
|
||||
)
|
||||
_sym_db.RegisterEnumDescriptor(_PERSON_PHONETYPE)
|
||||
|
||||
|
||||
_PERSON_PHONENUMBER = _descriptor.Descriptor(
|
||||
name='PhoneNumber',
|
||||
full_name='tutorial.Person.PhoneNumber',
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
containing_type=None,
|
||||
fields=[
|
||||
_descriptor.FieldDescriptor(
|
||||
name='number', full_name='tutorial.Person.PhoneNumber.number', index=0,
|
||||
number=1, type=9, cpp_type=9, label=2,
|
||||
has_default_value=False, default_value=_b("").decode('utf-8'),
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
options=None),
|
||||
_descriptor.FieldDescriptor(
|
||||
name='type', full_name='tutorial.Person.PhoneNumber.type', index=1,
|
||||
number=2, type=14, cpp_type=8, label=1,
|
||||
has_default_value=True, default_value=1,
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
options=None),
|
||||
],
|
||||
extensions=[
|
||||
],
|
||||
nested_types=[],
|
||||
enum_types=[
|
||||
],
|
||||
options=None,
|
||||
is_extendable=False,
|
||||
syntax='proto2',
|
||||
extension_ranges=[],
|
||||
oneofs=[
|
||||
],
|
||||
serialized_start=128,
|
||||
serialized_end=205,
|
||||
name="PhoneNumber",
|
||||
full_name="tutorial.Person.PhoneNumber",
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
containing_type=None,
|
||||
fields=[
|
||||
_descriptor.FieldDescriptor(
|
||||
name="number",
|
||||
full_name="tutorial.Person.PhoneNumber.number",
|
||||
index=0,
|
||||
number=1,
|
||||
type=9,
|
||||
cpp_type=9,
|
||||
label=2,
|
||||
has_default_value=False,
|
||||
default_value=_b("").decode("utf-8"),
|
||||
message_type=None,
|
||||
enum_type=None,
|
||||
containing_type=None,
|
||||
is_extension=False,
|
||||
extension_scope=None,
|
||||
options=None,
|
||||
),
|
||||
_descriptor.FieldDescriptor(
|
||||
name="type",
|
||||
full_name="tutorial.Person.PhoneNumber.type",
|
||||
index=1,
|
||||
number=2,
|
||||
type=14,
|
||||
cpp_type=8,
|
||||
label=1,
|
||||
has_default_value=True,
|
||||
default_value=1,
|
||||
message_type=None,
|
||||
enum_type=None,
|
||||
containing_type=None,
|
||||
is_extension=False,
|
||||
extension_scope=None,
|
||||
options=None,
|
||||
),
|
||||
],
|
||||
extensions=[],
|
||||
nested_types=[],
|
||||
enum_types=[],
|
||||
options=None,
|
||||
is_extendable=False,
|
||||
syntax="proto2",
|
||||
extension_ranges=[],
|
||||
oneofs=[],
|
||||
serialized_start=128,
|
||||
serialized_end=205,
|
||||
)
|
||||
|
||||
_PERSON = _descriptor.Descriptor(
|
||||
name='Person',
|
||||
full_name='tutorial.Person',
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
containing_type=None,
|
||||
fields=[
|
||||
_descriptor.FieldDescriptor(
|
||||
name='name', full_name='tutorial.Person.name', index=0,
|
||||
number=1, type=9, cpp_type=9, label=2,
|
||||
has_default_value=False, default_value=_b("").decode('utf-8'),
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
options=None),
|
||||
_descriptor.FieldDescriptor(
|
||||
name='id', full_name='tutorial.Person.id', index=1,
|
||||
number=2, type=5, cpp_type=1, label=2,
|
||||
has_default_value=False, default_value=0,
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
options=None),
|
||||
_descriptor.FieldDescriptor(
|
||||
name='email', full_name='tutorial.Person.email', index=2,
|
||||
number=3, type=9, cpp_type=9, label=2,
|
||||
has_default_value=False, default_value=_b("").decode('utf-8'),
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
options=None),
|
||||
_descriptor.FieldDescriptor(
|
||||
name='phone', full_name='tutorial.Person.phone', index=3,
|
||||
number=4, type=11, cpp_type=10, label=3,
|
||||
has_default_value=False, default_value=[],
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
options=None),
|
||||
],
|
||||
extensions=[
|
||||
],
|
||||
nested_types=[_PERSON_PHONENUMBER, ],
|
||||
enum_types=[
|
||||
_PERSON_PHONETYPE,
|
||||
],
|
||||
options=None,
|
||||
is_extendable=False,
|
||||
syntax='proto2',
|
||||
extension_ranges=[],
|
||||
oneofs=[
|
||||
],
|
||||
serialized_start=32,
|
||||
serialized_end=250,
|
||||
name="Person",
|
||||
full_name="tutorial.Person",
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
containing_type=None,
|
||||
fields=[
|
||||
_descriptor.FieldDescriptor(
|
||||
name="name",
|
||||
full_name="tutorial.Person.name",
|
||||
index=0,
|
||||
number=1,
|
||||
type=9,
|
||||
cpp_type=9,
|
||||
label=2,
|
||||
has_default_value=False,
|
||||
default_value=_b("").decode("utf-8"),
|
||||
message_type=None,
|
||||
enum_type=None,
|
||||
containing_type=None,
|
||||
is_extension=False,
|
||||
extension_scope=None,
|
||||
options=None,
|
||||
),
|
||||
_descriptor.FieldDescriptor(
|
||||
name="id",
|
||||
full_name="tutorial.Person.id",
|
||||
index=1,
|
||||
number=2,
|
||||
type=5,
|
||||
cpp_type=1,
|
||||
label=2,
|
||||
has_default_value=False,
|
||||
default_value=0,
|
||||
message_type=None,
|
||||
enum_type=None,
|
||||
containing_type=None,
|
||||
is_extension=False,
|
||||
extension_scope=None,
|
||||
options=None,
|
||||
),
|
||||
_descriptor.FieldDescriptor(
|
||||
name="email",
|
||||
full_name="tutorial.Person.email",
|
||||
index=2,
|
||||
number=3,
|
||||
type=9,
|
||||
cpp_type=9,
|
||||
label=2,
|
||||
has_default_value=False,
|
||||
default_value=_b("").decode("utf-8"),
|
||||
message_type=None,
|
||||
enum_type=None,
|
||||
containing_type=None,
|
||||
is_extension=False,
|
||||
extension_scope=None,
|
||||
options=None,
|
||||
),
|
||||
_descriptor.FieldDescriptor(
|
||||
name="phone",
|
||||
full_name="tutorial.Person.phone",
|
||||
index=3,
|
||||
number=4,
|
||||
type=11,
|
||||
cpp_type=10,
|
||||
label=3,
|
||||
has_default_value=False,
|
||||
default_value=[],
|
||||
message_type=None,
|
||||
enum_type=None,
|
||||
containing_type=None,
|
||||
is_extension=False,
|
||||
extension_scope=None,
|
||||
options=None,
|
||||
),
|
||||
],
|
||||
extensions=[],
|
||||
nested_types=[
|
||||
_PERSON_PHONENUMBER,
|
||||
],
|
||||
enum_types=[
|
||||
_PERSON_PHONETYPE,
|
||||
],
|
||||
options=None,
|
||||
is_extendable=False,
|
||||
syntax="proto2",
|
||||
extension_ranges=[],
|
||||
oneofs=[],
|
||||
serialized_start=32,
|
||||
serialized_end=250,
|
||||
)
|
||||
|
||||
|
||||
_ADDRESSBOOK = _descriptor.Descriptor(
|
||||
name='AddressBook',
|
||||
full_name='tutorial.AddressBook',
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
containing_type=None,
|
||||
fields=[
|
||||
_descriptor.FieldDescriptor(
|
||||
name='person', full_name='tutorial.AddressBook.person', index=0,
|
||||
number=1, type=11, cpp_type=10, label=3,
|
||||
has_default_value=False, default_value=[],
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
options=None),
|
||||
],
|
||||
extensions=[
|
||||
],
|
||||
nested_types=[],
|
||||
enum_types=[
|
||||
],
|
||||
options=None,
|
||||
is_extendable=False,
|
||||
syntax='proto2',
|
||||
extension_ranges=[],
|
||||
oneofs=[
|
||||
],
|
||||
serialized_start=252,
|
||||
serialized_end=299,
|
||||
name="AddressBook",
|
||||
full_name="tutorial.AddressBook",
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
containing_type=None,
|
||||
fields=[
|
||||
_descriptor.FieldDescriptor(
|
||||
name="person",
|
||||
full_name="tutorial.AddressBook.person",
|
||||
index=0,
|
||||
number=1,
|
||||
type=11,
|
||||
cpp_type=10,
|
||||
label=3,
|
||||
has_default_value=False,
|
||||
default_value=[],
|
||||
message_type=None,
|
||||
enum_type=None,
|
||||
containing_type=None,
|
||||
is_extension=False,
|
||||
extension_scope=None,
|
||||
options=None,
|
||||
),
|
||||
],
|
||||
extensions=[],
|
||||
nested_types=[],
|
||||
enum_types=[],
|
||||
options=None,
|
||||
is_extendable=False,
|
||||
syntax="proto2",
|
||||
extension_ranges=[],
|
||||
oneofs=[],
|
||||
serialized_start=252,
|
||||
serialized_end=299,
|
||||
)
|
||||
|
||||
_PERSON_PHONENUMBER.fields_by_name['type'].enum_type = _PERSON_PHONETYPE
|
||||
_PERSON_PHONENUMBER.fields_by_name["type"].enum_type = _PERSON_PHONETYPE
|
||||
_PERSON_PHONENUMBER.containing_type = _PERSON
|
||||
_PERSON.fields_by_name['phone'].message_type = _PERSON_PHONENUMBER
|
||||
_PERSON.fields_by_name["phone"].message_type = _PERSON_PHONENUMBER
|
||||
_PERSON_PHONETYPE.containing_type = _PERSON
|
||||
_ADDRESSBOOK.fields_by_name['person'].message_type = _PERSON
|
||||
DESCRIPTOR.message_types_by_name['Person'] = _PERSON
|
||||
DESCRIPTOR.message_types_by_name['AddressBook'] = _ADDRESSBOOK
|
||||
_ADDRESSBOOK.fields_by_name["person"].message_type = _PERSON
|
||||
DESCRIPTOR.message_types_by_name["Person"] = _PERSON
|
||||
DESCRIPTOR.message_types_by_name["AddressBook"] = _ADDRESSBOOK
|
||||
_sym_db.RegisterFileDescriptor(DESCRIPTOR)
|
||||
|
||||
Person = _reflection.GeneratedProtocolMessageType('Person', (_message.Message,), dict(
|
||||
|
||||
PhoneNumber = _reflection.GeneratedProtocolMessageType('PhoneNumber', (_message.Message,), dict(
|
||||
DESCRIPTOR = _PERSON_PHONENUMBER,
|
||||
__module__ = 'addressbook_pb2'
|
||||
# @@protoc_insertion_point(class_scope:tutorial.Person.PhoneNumber)
|
||||
))
|
||||
,
|
||||
DESCRIPTOR = _PERSON,
|
||||
__module__ = 'addressbook_pb2'
|
||||
# @@protoc_insertion_point(class_scope:tutorial.Person)
|
||||
))
|
||||
Person = _reflection.GeneratedProtocolMessageType(
|
||||
"Person",
|
||||
(_message.Message,),
|
||||
dict(
|
||||
PhoneNumber=_reflection.GeneratedProtocolMessageType(
|
||||
"PhoneNumber",
|
||||
(_message.Message,),
|
||||
dict(
|
||||
DESCRIPTOR=_PERSON_PHONENUMBER,
|
||||
__module__="addressbook_pb2"
|
||||
# @@protoc_insertion_point(class_scope:tutorial.Person.PhoneNumber)
|
||||
),
|
||||
),
|
||||
DESCRIPTOR=_PERSON,
|
||||
__module__="addressbook_pb2"
|
||||
# @@protoc_insertion_point(class_scope:tutorial.Person)
|
||||
),
|
||||
)
|
||||
_sym_db.RegisterMessage(Person)
|
||||
_sym_db.RegisterMessage(Person.PhoneNumber)
|
||||
|
||||
AddressBook = _reflection.GeneratedProtocolMessageType('AddressBook', (_message.Message,), dict(
|
||||
DESCRIPTOR = _ADDRESSBOOK,
|
||||
__module__ = 'addressbook_pb2'
|
||||
# @@protoc_insertion_point(class_scope:tutorial.AddressBook)
|
||||
))
|
||||
AddressBook = _reflection.GeneratedProtocolMessageType(
|
||||
"AddressBook",
|
||||
(_message.Message,),
|
||||
dict(
|
||||
DESCRIPTOR=_ADDRESSBOOK,
|
||||
__module__="addressbook_pb2"
|
||||
# @@protoc_insertion_point(class_scope:tutorial.AddressBook)
|
||||
),
|
||||
)
|
||||
_sym_db.RegisterMessage(AddressBook)
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -6,7 +6,18 @@ from random import choice
|
||||
|
||||
MAKES = ["Toyota", "GM", "Ford", "Honda", "Tesla"]
|
||||
MODELS = ["Camry", "Prius", "Volt", "Accord", "Leaf", "Model S"]
|
||||
COLORS = ["black", "white", "red", "green", "blue", "cyan", "magenta", "yellow", "silver"]
|
||||
COLORS = [
|
||||
"black",
|
||||
"white",
|
||||
"red",
|
||||
"green",
|
||||
"blue",
|
||||
"cyan",
|
||||
"magenta",
|
||||
"yellow",
|
||||
"silver",
|
||||
]
|
||||
|
||||
|
||||
def random_car(car):
|
||||
car.make = choice(MAKES)
|
||||
@@ -42,6 +53,7 @@ def random_car(car):
|
||||
car.cup_holders = rand_int(12)
|
||||
car.has_nav_system = rand_bool()
|
||||
|
||||
|
||||
def calc_value(car):
|
||||
result = 0
|
||||
|
||||
@@ -57,9 +69,9 @@ def calc_value(car):
|
||||
result += engine.horsepower * 40
|
||||
if engine.uses_electric:
|
||||
if engine.uses_gas:
|
||||
result += 5000
|
||||
result += 5000
|
||||
else:
|
||||
result += 3000
|
||||
result += 3000
|
||||
|
||||
result += 100 if car.has_power_windows else 0
|
||||
result += 200 if car.has_power_steering else 0
|
||||
@@ -70,6 +82,7 @@ def calc_value(car):
|
||||
|
||||
return result
|
||||
|
||||
|
||||
class Benchmark:
|
||||
def __init__(self, compression):
|
||||
self.Request = carsales_pb2.ParkingLot
|
||||
@@ -81,17 +94,17 @@ class Benchmark:
|
||||
def setup(self, request):
|
||||
result = 0
|
||||
for _ in range(rand_int(200)):
|
||||
car = request.car.add()
|
||||
random_car(car)
|
||||
result += calc_value(car)
|
||||
car = request.car.add()
|
||||
random_car(car)
|
||||
result += calc_value(car)
|
||||
return result
|
||||
|
||||
def handle(self, request, response):
|
||||
result = 0
|
||||
for car in request.car:
|
||||
result += calc_value(car)
|
||||
result += calc_value(car)
|
||||
|
||||
response.amount = result
|
||||
|
||||
def check(self, response, expected):
|
||||
return response.amount == expected
|
||||
return response.amount == expected
|
||||
|
||||
@@ -7,7 +7,18 @@ from random import choice
|
||||
|
||||
MAKES = ["Toyota", "GM", "Ford", "Honda", "Tesla"]
|
||||
MODELS = ["Camry", "Prius", "Volt", "Accord", "Leaf", "Model S"]
|
||||
COLORS = ["black", "white", "red", "green", "blue", "cyan", "magenta", "yellow", "silver"]
|
||||
COLORS = [
|
||||
"black",
|
||||
"white",
|
||||
"red",
|
||||
"green",
|
||||
"blue",
|
||||
"cyan",
|
||||
"magenta",
|
||||
"yellow",
|
||||
"silver",
|
||||
]
|
||||
|
||||
|
||||
def random_car(car):
|
||||
car.make = choice(MAKES)
|
||||
@@ -17,7 +28,7 @@ def random_car(car):
|
||||
car.seats = 2 + rand_int(6)
|
||||
car.doors = 2 + rand_int(3)
|
||||
|
||||
for wheel in car.init('wheels', 4):
|
||||
for wheel in car.init("wheels", 4):
|
||||
wheel.diameter = 25 + rand_int(15)
|
||||
wheel.airPressure = 30 + rand_double(20)
|
||||
wheel.snowTires = rand_int(16) == 0
|
||||
@@ -27,7 +38,7 @@ def random_car(car):
|
||||
car.height = 54 + rand_int(48)
|
||||
car.weight = car.length * car.width * car.height // 200
|
||||
|
||||
engine = car.init('engine')
|
||||
engine = car.init("engine")
|
||||
engine.horsepower = 100 * rand_int(400)
|
||||
engine.cylinders = 4 + 2 * rand_int(3)
|
||||
engine.cc = 800 + rand_int(10000)
|
||||
@@ -42,6 +53,7 @@ def random_car(car):
|
||||
car.cupHolders = rand_int(12)
|
||||
car.hasNavSystem = rand_bool()
|
||||
|
||||
|
||||
def calc_value(car):
|
||||
result = 0
|
||||
|
||||
@@ -57,9 +69,9 @@ def calc_value(car):
|
||||
result += engine.horsepower * 40
|
||||
if engine.usesElectric:
|
||||
if engine.usesGas:
|
||||
result += 5000
|
||||
result += 5000
|
||||
else:
|
||||
result += 3000
|
||||
result += 3000
|
||||
|
||||
result += 100 if car.hasPowerWindows else 0
|
||||
result += 200 if car.hasPowerSteering else 0
|
||||
@@ -70,11 +82,12 @@ def calc_value(car):
|
||||
|
||||
return result
|
||||
|
||||
|
||||
class Benchmark:
|
||||
def __init__(self, compression):
|
||||
self.Request = carsales_capnp.ParkingLot.new_message
|
||||
self.Response = carsales_capnp.TotalValue.new_message
|
||||
if compression == 'packed':
|
||||
if compression == "packed":
|
||||
self.from_bytes_request = carsales_capnp.ParkingLot.from_bytes_packed
|
||||
self.from_bytes_response = carsales_capnp.TotalValue.from_bytes_packed
|
||||
self.to_bytes = lambda x: x.to_bytes_packed()
|
||||
@@ -85,17 +98,17 @@ class Benchmark:
|
||||
|
||||
def setup(self, request):
|
||||
result = 0
|
||||
for car in request.init('cars', rand_int(200)):
|
||||
random_car(car)
|
||||
result += calc_value(car)
|
||||
for car in request.init("cars", rand_int(200)):
|
||||
random_car(car)
|
||||
result += calc_value(car)
|
||||
return result
|
||||
|
||||
def handle(self, request, response):
|
||||
result = 0
|
||||
for car in request.cars:
|
||||
result += calc_value(car)
|
||||
result += calc_value(car)
|
||||
|
||||
response.amount = result
|
||||
|
||||
def check(self, response, expected):
|
||||
return response.amount == expected
|
||||
return response.amount == expected
|
||||
|
||||
@@ -2,121 +2,163 @@
|
||||
# source: catrank.proto
|
||||
|
||||
import sys
|
||||
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
|
||||
|
||||
_b = sys.version_info[0] < 3 and (lambda x: x) or (lambda x: x.encode("latin1"))
|
||||
from google.protobuf import descriptor as _descriptor
|
||||
from google.protobuf import message as _message
|
||||
from google.protobuf import reflection as _reflection
|
||||
from google.protobuf import symbol_database as _symbol_database
|
||||
from google.protobuf import descriptor_pb2
|
||||
|
||||
# @@protoc_insertion_point(imports)
|
||||
|
||||
_sym_db = _symbol_database.Default()
|
||||
|
||||
|
||||
|
||||
|
||||
DESCRIPTOR = _descriptor.FileDescriptor(
|
||||
name='catrank.proto',
|
||||
package='capnp.benchmark.protobuf',
|
||||
syntax='proto2',
|
||||
serialized_pb=_b('\n\rcatrank.proto\x12\x18\x63\x61pnp.benchmark.protobuf\"J\n\x10SearchResultList\x12\x36\n\x06result\x18\x01 \x03(\x0b\x32&.capnp.benchmark.protobuf.SearchResult\";\n\x0cSearchResult\x12\x0b\n\x03url\x18\x01 \x01(\t\x12\r\n\x05score\x18\x02 \x01(\x01\x12\x0f\n\x07snippet\x18\x03 \x01(\t')
|
||||
name="catrank.proto",
|
||||
package="capnp.benchmark.protobuf",
|
||||
syntax="proto2",
|
||||
serialized_pb=_b(
|
||||
'\n\rcatrank.proto\x12\x18\x63\x61pnp.benchmark.protobuf"J\n\x10SearchResultList\x12\x36\n\x06result\x18\x01 \x03(\x0b\x32&.capnp.benchmark.protobuf.SearchResult";\n\x0cSearchResult\x12\x0b\n\x03url\x18\x01 \x01(\t\x12\r\n\x05score\x18\x02 \x01(\x01\x12\x0f\n\x07snippet\x18\x03 \x01(\t'
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
_SEARCHRESULTLIST = _descriptor.Descriptor(
|
||||
name='SearchResultList',
|
||||
full_name='capnp.benchmark.protobuf.SearchResultList',
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
containing_type=None,
|
||||
fields=[
|
||||
_descriptor.FieldDescriptor(
|
||||
name='result', full_name='capnp.benchmark.protobuf.SearchResultList.result', index=0,
|
||||
number=1, type=11, cpp_type=10, label=3,
|
||||
has_default_value=False, default_value=[],
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
options=None),
|
||||
],
|
||||
extensions=[
|
||||
],
|
||||
nested_types=[],
|
||||
enum_types=[
|
||||
],
|
||||
options=None,
|
||||
is_extendable=False,
|
||||
syntax='proto2',
|
||||
extension_ranges=[],
|
||||
oneofs=[
|
||||
],
|
||||
serialized_start=43,
|
||||
serialized_end=117,
|
||||
name="SearchResultList",
|
||||
full_name="capnp.benchmark.protobuf.SearchResultList",
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
containing_type=None,
|
||||
fields=[
|
||||
_descriptor.FieldDescriptor(
|
||||
name="result",
|
||||
full_name="capnp.benchmark.protobuf.SearchResultList.result",
|
||||
index=0,
|
||||
number=1,
|
||||
type=11,
|
||||
cpp_type=10,
|
||||
label=3,
|
||||
has_default_value=False,
|
||||
default_value=[],
|
||||
message_type=None,
|
||||
enum_type=None,
|
||||
containing_type=None,
|
||||
is_extension=False,
|
||||
extension_scope=None,
|
||||
options=None,
|
||||
),
|
||||
],
|
||||
extensions=[],
|
||||
nested_types=[],
|
||||
enum_types=[],
|
||||
options=None,
|
||||
is_extendable=False,
|
||||
syntax="proto2",
|
||||
extension_ranges=[],
|
||||
oneofs=[],
|
||||
serialized_start=43,
|
||||
serialized_end=117,
|
||||
)
|
||||
|
||||
|
||||
_SEARCHRESULT = _descriptor.Descriptor(
|
||||
name='SearchResult',
|
||||
full_name='capnp.benchmark.protobuf.SearchResult',
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
containing_type=None,
|
||||
fields=[
|
||||
_descriptor.FieldDescriptor(
|
||||
name='url', full_name='capnp.benchmark.protobuf.SearchResult.url', index=0,
|
||||
number=1, type=9, cpp_type=9, label=1,
|
||||
has_default_value=False, default_value=_b("").decode('utf-8'),
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
options=None),
|
||||
_descriptor.FieldDescriptor(
|
||||
name='score', full_name='capnp.benchmark.protobuf.SearchResult.score', index=1,
|
||||
number=2, type=1, cpp_type=5, label=1,
|
||||
has_default_value=False, default_value=float(0),
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
options=None),
|
||||
_descriptor.FieldDescriptor(
|
||||
name='snippet', full_name='capnp.benchmark.protobuf.SearchResult.snippet', index=2,
|
||||
number=3, type=9, cpp_type=9, label=1,
|
||||
has_default_value=False, default_value=_b("").decode('utf-8'),
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
options=None),
|
||||
],
|
||||
extensions=[
|
||||
],
|
||||
nested_types=[],
|
||||
enum_types=[
|
||||
],
|
||||
options=None,
|
||||
is_extendable=False,
|
||||
syntax='proto2',
|
||||
extension_ranges=[],
|
||||
oneofs=[
|
||||
],
|
||||
serialized_start=119,
|
||||
serialized_end=178,
|
||||
name="SearchResult",
|
||||
full_name="capnp.benchmark.protobuf.SearchResult",
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
containing_type=None,
|
||||
fields=[
|
||||
_descriptor.FieldDescriptor(
|
||||
name="url",
|
||||
full_name="capnp.benchmark.protobuf.SearchResult.url",
|
||||
index=0,
|
||||
number=1,
|
||||
type=9,
|
||||
cpp_type=9,
|
||||
label=1,
|
||||
has_default_value=False,
|
||||
default_value=_b("").decode("utf-8"),
|
||||
message_type=None,
|
||||
enum_type=None,
|
||||
containing_type=None,
|
||||
is_extension=False,
|
||||
extension_scope=None,
|
||||
options=None,
|
||||
),
|
||||
_descriptor.FieldDescriptor(
|
||||
name="score",
|
||||
full_name="capnp.benchmark.protobuf.SearchResult.score",
|
||||
index=1,
|
||||
number=2,
|
||||
type=1,
|
||||
cpp_type=5,
|
||||
label=1,
|
||||
has_default_value=False,
|
||||
default_value=float(0),
|
||||
message_type=None,
|
||||
enum_type=None,
|
||||
containing_type=None,
|
||||
is_extension=False,
|
||||
extension_scope=None,
|
||||
options=None,
|
||||
),
|
||||
_descriptor.FieldDescriptor(
|
||||
name="snippet",
|
||||
full_name="capnp.benchmark.protobuf.SearchResult.snippet",
|
||||
index=2,
|
||||
number=3,
|
||||
type=9,
|
||||
cpp_type=9,
|
||||
label=1,
|
||||
has_default_value=False,
|
||||
default_value=_b("").decode("utf-8"),
|
||||
message_type=None,
|
||||
enum_type=None,
|
||||
containing_type=None,
|
||||
is_extension=False,
|
||||
extension_scope=None,
|
||||
options=None,
|
||||
),
|
||||
],
|
||||
extensions=[],
|
||||
nested_types=[],
|
||||
enum_types=[],
|
||||
options=None,
|
||||
is_extendable=False,
|
||||
syntax="proto2",
|
||||
extension_ranges=[],
|
||||
oneofs=[],
|
||||
serialized_start=119,
|
||||
serialized_end=178,
|
||||
)
|
||||
|
||||
_SEARCHRESULTLIST.fields_by_name['result'].message_type = _SEARCHRESULT
|
||||
DESCRIPTOR.message_types_by_name['SearchResultList'] = _SEARCHRESULTLIST
|
||||
DESCRIPTOR.message_types_by_name['SearchResult'] = _SEARCHRESULT
|
||||
_SEARCHRESULTLIST.fields_by_name["result"].message_type = _SEARCHRESULT
|
||||
DESCRIPTOR.message_types_by_name["SearchResultList"] = _SEARCHRESULTLIST
|
||||
DESCRIPTOR.message_types_by_name["SearchResult"] = _SEARCHRESULT
|
||||
_sym_db.RegisterFileDescriptor(DESCRIPTOR)
|
||||
|
||||
SearchResultList = _reflection.GeneratedProtocolMessageType('SearchResultList', (_message.Message,), dict(
|
||||
DESCRIPTOR = _SEARCHRESULTLIST,
|
||||
__module__ = 'catrank_pb2'
|
||||
# @@protoc_insertion_point(class_scope:capnp.benchmark.protobuf.SearchResultList)
|
||||
))
|
||||
SearchResultList = _reflection.GeneratedProtocolMessageType(
|
||||
"SearchResultList",
|
||||
(_message.Message,),
|
||||
dict(
|
||||
DESCRIPTOR=_SEARCHRESULTLIST,
|
||||
__module__="catrank_pb2"
|
||||
# @@protoc_insertion_point(class_scope:capnp.benchmark.protobuf.SearchResultList)
|
||||
),
|
||||
)
|
||||
_sym_db.RegisterMessage(SearchResultList)
|
||||
|
||||
SearchResult = _reflection.GeneratedProtocolMessageType('SearchResult', (_message.Message,), dict(
|
||||
DESCRIPTOR = _SEARCHRESULT,
|
||||
__module__ = 'catrank_pb2'
|
||||
# @@protoc_insertion_point(class_scope:capnp.benchmark.protobuf.SearchResult)
|
||||
))
|
||||
SearchResult = _reflection.GeneratedProtocolMessageType(
|
||||
"SearchResult",
|
||||
(_message.Message,),
|
||||
dict(
|
||||
DESCRIPTOR=_SEARCHRESULT,
|
||||
__module__="catrank_pb2"
|
||||
# @@protoc_insertion_point(class_scope:capnp.benchmark.protobuf.SearchResult)
|
||||
),
|
||||
)
|
||||
_sym_db.RegisterMessage(SearchResult)
|
||||
|
||||
|
||||
|
||||
@@ -3,13 +3,15 @@
|
||||
from common import rand_int, rand_double, rand_bool, WORDS, from_bytes_helper
|
||||
from random import choice
|
||||
from string import ascii_letters
|
||||
|
||||
try:
|
||||
# Python 2
|
||||
from itertools import izip
|
||||
# Python 2
|
||||
from itertools import izip
|
||||
except ImportError:
|
||||
izip = zip
|
||||
izip = zip
|
||||
import catrank_pb2
|
||||
|
||||
|
||||
class Benchmark:
|
||||
def __init__(self, compression):
|
||||
self.Request = catrank_pb2.SearchResultList
|
||||
@@ -26,7 +28,9 @@ class Benchmark:
|
||||
result = request.result.add()
|
||||
result.score = 1000 - i
|
||||
url_size = rand_int(100)
|
||||
result.url = "http://example.com/" + ''.join([choice(ascii_letters) for _ in range(url_size)])
|
||||
result.url = "http://example.com/" + "".join(
|
||||
[choice(ascii_letters) for _ in range(url_size)]
|
||||
)
|
||||
|
||||
isCat = rand_bool()
|
||||
isDog = rand_bool()
|
||||
@@ -42,7 +46,7 @@ class Benchmark:
|
||||
|
||||
snippet += [choice(WORDS) for i in range(rand_int(20))]
|
||||
|
||||
result.snippet = ''.join(snippet)
|
||||
result.snippet = "".join(snippet)
|
||||
|
||||
return goodCount
|
||||
|
||||
@@ -60,10 +64,9 @@ class Benchmark:
|
||||
resp.url = req.url
|
||||
resp.snippet = req.snippet
|
||||
|
||||
|
||||
def check(self, response, expected):
|
||||
goodCount = 0
|
||||
|
||||
|
||||
for result in response.result:
|
||||
if result.score > 1001:
|
||||
goodCount += 1
|
||||
|
||||
@@ -5,17 +5,19 @@ import catrank_capnp
|
||||
from common import rand_int, rand_double, rand_bool, WORDS
|
||||
from random import choice
|
||||
from string import ascii_letters
|
||||
|
||||
try:
|
||||
# Python 2
|
||||
from itertools import izip
|
||||
# Python 2
|
||||
from itertools import izip
|
||||
except ImportError:
|
||||
izip = zip
|
||||
izip = zip
|
||||
|
||||
|
||||
class Benchmark:
|
||||
def __init__(self, compression):
|
||||
self.Request = catrank_capnp.SearchResultList.new_message
|
||||
self.Response = catrank_capnp.SearchResultList.new_message
|
||||
if compression == 'packed':
|
||||
if compression == "packed":
|
||||
self.from_bytes_request = catrank_capnp.SearchResultList.from_bytes_packed
|
||||
self.from_bytes_response = catrank_capnp.SearchResultList.from_bytes_packed
|
||||
self.to_bytes = lambda x: x.to_bytes_packed()
|
||||
@@ -28,12 +30,14 @@ class Benchmark:
|
||||
goodCount = 0
|
||||
count = rand_int(1000)
|
||||
|
||||
results = request.init('results', count)
|
||||
results = request.init("results", count)
|
||||
|
||||
for i, result in enumerate(results):
|
||||
result.score = 1000 - i
|
||||
url_size = rand_int(100)
|
||||
result.url = "http://example.com/" + ''.join([choice(ascii_letters) for _ in range(url_size)])
|
||||
result.url = "http://example.com/" + "".join(
|
||||
[choice(ascii_letters) for _ in range(url_size)]
|
||||
)
|
||||
|
||||
isCat = rand_bool()
|
||||
isDog = rand_bool()
|
||||
@@ -49,12 +53,12 @@ class Benchmark:
|
||||
|
||||
snippet += [choice(WORDS) for i in range(rand_int(20))]
|
||||
|
||||
result.snippet = ''.join(snippet)
|
||||
result.snippet = "".join(snippet)
|
||||
|
||||
return goodCount
|
||||
|
||||
def handle(self, request, response):
|
||||
results = response.init('results', len(request.results))
|
||||
results = response.init("results", len(request.results))
|
||||
|
||||
for req, resp in izip(request.results, results):
|
||||
score = req.score
|
||||
@@ -68,7 +72,6 @@ class Benchmark:
|
||||
resp.url = req.url
|
||||
resp.snippet = req.snippet
|
||||
|
||||
|
||||
def check(self, response, expected):
|
||||
goodCount = 0
|
||||
|
||||
|
||||
@@ -1,19 +1,37 @@
|
||||
from random import random
|
||||
import pyximport
|
||||
|
||||
importers = pyximport.install()
|
||||
from common_fast import rand_int, rand_double, rand_bool
|
||||
from common_fast import rand_int, rand_double, rand_bool
|
||||
|
||||
pyximport.uninstall(*importers)
|
||||
|
||||
WORDS = ["foo ", "bar ", "baz ", "qux ", "quux ", "corge ", "grault ", "garply ", "waldo ", "fred ",
|
||||
"plugh ", "xyzzy ", "thud "]
|
||||
WORDS = [
|
||||
"foo ",
|
||||
"bar ",
|
||||
"baz ",
|
||||
"qux ",
|
||||
"quux ",
|
||||
"corge ",
|
||||
"grault ",
|
||||
"garply ",
|
||||
"waldo ",
|
||||
"fred ",
|
||||
"plugh ",
|
||||
"xyzzy ",
|
||||
"thud ",
|
||||
]
|
||||
|
||||
|
||||
def from_bytes_helper(klass):
|
||||
def helper(text):
|
||||
obj = klass()
|
||||
obj.ParseFromString(text)
|
||||
return obj
|
||||
|
||||
return helper
|
||||
|
||||
|
||||
def pass_by_object(reuse, iters, benchmark):
|
||||
for _ in range(iters):
|
||||
request = benchmark.Request()
|
||||
@@ -23,7 +41,8 @@ def pass_by_object(reuse, iters, benchmark):
|
||||
benchmark.handle(request, response)
|
||||
|
||||
if not benchmark.check(response, expected):
|
||||
raise ValueError('Expected {}'.format(expected))
|
||||
raise ValueError("Expected {}".format(expected))
|
||||
|
||||
|
||||
def pass_by_bytes(reuse, iters, benchmark):
|
||||
for _ in range(iters):
|
||||
@@ -38,7 +57,8 @@ def pass_by_bytes(reuse, iters, benchmark):
|
||||
|
||||
response2 = benchmark.from_bytes_response(resp_bytes)
|
||||
if not benchmark.check(response2, expected):
|
||||
raise ValueError('Expected {}'.format(expected))
|
||||
raise ValueError("Expected {}".format(expected))
|
||||
|
||||
|
||||
def do_benchmark(mode, *args, **kwargs):
|
||||
if mode == "client":
|
||||
@@ -49,6 +69,8 @@ def do_benchmark(mode, *args, **kwargs):
|
||||
return pass_by_bytes(*args, **kwargs)
|
||||
else:
|
||||
raise ValueError("Unknown mode: " + str(mode))
|
||||
|
||||
|
||||
# typedef typename BenchmarkTypes::template BenchmarkMethods<TestCase, Reuse, Compression>
|
||||
# BenchmarkMethods;
|
||||
# if (mode == "client") {
|
||||
@@ -69,4 +91,4 @@ def do_benchmark(mode, *args, **kwargs):
|
||||
# fprintf(stderr, "Unknown mode: %s\n", mode.c_str());
|
||||
# exit(1);
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
|
||||
@@ -2,58 +2,55 @@
|
||||
# source: eval.proto
|
||||
|
||||
import sys
|
||||
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
|
||||
|
||||
_b = sys.version_info[0] < 3 and (lambda x: x) or (lambda x: x.encode("latin1"))
|
||||
from google.protobuf.internal import enum_type_wrapper
|
||||
from google.protobuf import descriptor as _descriptor
|
||||
from google.protobuf import message as _message
|
||||
from google.protobuf import reflection as _reflection
|
||||
from google.protobuf import symbol_database as _symbol_database
|
||||
from google.protobuf import descriptor_pb2
|
||||
|
||||
# @@protoc_insertion_point(imports)
|
||||
|
||||
_sym_db = _symbol_database.Default()
|
||||
|
||||
|
||||
|
||||
|
||||
DESCRIPTOR = _descriptor.FileDescriptor(
|
||||
name='eval.proto',
|
||||
package='capnp.benchmark.protobuf',
|
||||
syntax='proto2',
|
||||
serialized_pb=_b('\n\neval.proto\x12\x18\x63\x61pnp.benchmark.protobuf\"\xe5\x01\n\nExpression\x12/\n\x02op\x18\x01 \x02(\x0e\x32#.capnp.benchmark.protobuf.Operation\x12\x12\n\nleft_value\x18\x02 \x01(\x05\x12=\n\x0fleft_expression\x18\x03 \x01(\x0b\x32$.capnp.benchmark.protobuf.Expression\x12\x13\n\x0bright_value\x18\x04 \x01(\x05\x12>\n\x10right_expression\x18\x05 \x01(\x0b\x32$.capnp.benchmark.protobuf.Expression\"!\n\x10\x45valuationResult\x12\r\n\x05value\x18\x01 \x02(\x11*I\n\tOperation\x12\x07\n\x03\x41\x44\x44\x10\x00\x12\x0c\n\x08SUBTRACT\x10\x01\x12\x0c\n\x08MULTIPLY\x10\x02\x12\n\n\x06\x44IVIDE\x10\x03\x12\x0b\n\x07MODULUS\x10\x04')
|
||||
name="eval.proto",
|
||||
package="capnp.benchmark.protobuf",
|
||||
syntax="proto2",
|
||||
serialized_pb=_b(
|
||||
'\n\neval.proto\x12\x18\x63\x61pnp.benchmark.protobuf"\xe5\x01\n\nExpression\x12/\n\x02op\x18\x01 \x02(\x0e\x32#.capnp.benchmark.protobuf.Operation\x12\x12\n\nleft_value\x18\x02 \x01(\x05\x12=\n\x0fleft_expression\x18\x03 \x01(\x0b\x32$.capnp.benchmark.protobuf.Expression\x12\x13\n\x0bright_value\x18\x04 \x01(\x05\x12>\n\x10right_expression\x18\x05 \x01(\x0b\x32$.capnp.benchmark.protobuf.Expression"!\n\x10\x45valuationResult\x12\r\n\x05value\x18\x01 \x02(\x11*I\n\tOperation\x12\x07\n\x03\x41\x44\x44\x10\x00\x12\x0c\n\x08SUBTRACT\x10\x01\x12\x0c\n\x08MULTIPLY\x10\x02\x12\n\n\x06\x44IVIDE\x10\x03\x12\x0b\n\x07MODULUS\x10\x04'
|
||||
),
|
||||
)
|
||||
|
||||
_OPERATION = _descriptor.EnumDescriptor(
|
||||
name='Operation',
|
||||
full_name='capnp.benchmark.protobuf.Operation',
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
values=[
|
||||
_descriptor.EnumValueDescriptor(
|
||||
name='ADD', index=0, number=0,
|
||||
options=None,
|
||||
type=None),
|
||||
_descriptor.EnumValueDescriptor(
|
||||
name='SUBTRACT', index=1, number=1,
|
||||
options=None,
|
||||
type=None),
|
||||
_descriptor.EnumValueDescriptor(
|
||||
name='MULTIPLY', index=2, number=2,
|
||||
options=None,
|
||||
type=None),
|
||||
_descriptor.EnumValueDescriptor(
|
||||
name='DIVIDE', index=3, number=3,
|
||||
options=None,
|
||||
type=None),
|
||||
_descriptor.EnumValueDescriptor(
|
||||
name='MODULUS', index=4, number=4,
|
||||
options=None,
|
||||
type=None),
|
||||
],
|
||||
containing_type=None,
|
||||
options=None,
|
||||
serialized_start=307,
|
||||
serialized_end=380,
|
||||
name="Operation",
|
||||
full_name="capnp.benchmark.protobuf.Operation",
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
values=[
|
||||
_descriptor.EnumValueDescriptor(
|
||||
name="ADD", index=0, number=0, options=None, type=None
|
||||
),
|
||||
_descriptor.EnumValueDescriptor(
|
||||
name="SUBTRACT", index=1, number=1, options=None, type=None
|
||||
),
|
||||
_descriptor.EnumValueDescriptor(
|
||||
name="MULTIPLY", index=2, number=2, options=None, type=None
|
||||
),
|
||||
_descriptor.EnumValueDescriptor(
|
||||
name="DIVIDE", index=3, number=3, options=None, type=None
|
||||
),
|
||||
_descriptor.EnumValueDescriptor(
|
||||
name="MODULUS", index=4, number=4, options=None, type=None
|
||||
),
|
||||
],
|
||||
containing_type=None,
|
||||
options=None,
|
||||
serialized_start=307,
|
||||
serialized_end=380,
|
||||
)
|
||||
_sym_db.RegisterEnumDescriptor(_OPERATION)
|
||||
|
||||
@@ -65,116 +62,177 @@ DIVIDE = 3
|
||||
MODULUS = 4
|
||||
|
||||
|
||||
|
||||
_EXPRESSION = _descriptor.Descriptor(
|
||||
name='Expression',
|
||||
full_name='capnp.benchmark.protobuf.Expression',
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
containing_type=None,
|
||||
fields=[
|
||||
_descriptor.FieldDescriptor(
|
||||
name='op', full_name='capnp.benchmark.protobuf.Expression.op', index=0,
|
||||
number=1, type=14, cpp_type=8, label=2,
|
||||
has_default_value=False, default_value=0,
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
options=None),
|
||||
_descriptor.FieldDescriptor(
|
||||
name='left_value', full_name='capnp.benchmark.protobuf.Expression.left_value', index=1,
|
||||
number=2, type=5, cpp_type=1, label=1,
|
||||
has_default_value=False, default_value=0,
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
options=None),
|
||||
_descriptor.FieldDescriptor(
|
||||
name='left_expression', full_name='capnp.benchmark.protobuf.Expression.left_expression', index=2,
|
||||
number=3, type=11, cpp_type=10, label=1,
|
||||
has_default_value=False, default_value=None,
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
options=None),
|
||||
_descriptor.FieldDescriptor(
|
||||
name='right_value', full_name='capnp.benchmark.protobuf.Expression.right_value', index=3,
|
||||
number=4, type=5, cpp_type=1, label=1,
|
||||
has_default_value=False, default_value=0,
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
options=None),
|
||||
_descriptor.FieldDescriptor(
|
||||
name='right_expression', full_name='capnp.benchmark.protobuf.Expression.right_expression', index=4,
|
||||
number=5, type=11, cpp_type=10, label=1,
|
||||
has_default_value=False, default_value=None,
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
options=None),
|
||||
],
|
||||
extensions=[
|
||||
],
|
||||
nested_types=[],
|
||||
enum_types=[
|
||||
],
|
||||
options=None,
|
||||
is_extendable=False,
|
||||
syntax='proto2',
|
||||
extension_ranges=[],
|
||||
oneofs=[
|
||||
],
|
||||
serialized_start=41,
|
||||
serialized_end=270,
|
||||
name="Expression",
|
||||
full_name="capnp.benchmark.protobuf.Expression",
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
containing_type=None,
|
||||
fields=[
|
||||
_descriptor.FieldDescriptor(
|
||||
name="op",
|
||||
full_name="capnp.benchmark.protobuf.Expression.op",
|
||||
index=0,
|
||||
number=1,
|
||||
type=14,
|
||||
cpp_type=8,
|
||||
label=2,
|
||||
has_default_value=False,
|
||||
default_value=0,
|
||||
message_type=None,
|
||||
enum_type=None,
|
||||
containing_type=None,
|
||||
is_extension=False,
|
||||
extension_scope=None,
|
||||
options=None,
|
||||
),
|
||||
_descriptor.FieldDescriptor(
|
||||
name="left_value",
|
||||
full_name="capnp.benchmark.protobuf.Expression.left_value",
|
||||
index=1,
|
||||
number=2,
|
||||
type=5,
|
||||
cpp_type=1,
|
||||
label=1,
|
||||
has_default_value=False,
|
||||
default_value=0,
|
||||
message_type=None,
|
||||
enum_type=None,
|
||||
containing_type=None,
|
||||
is_extension=False,
|
||||
extension_scope=None,
|
||||
options=None,
|
||||
),
|
||||
_descriptor.FieldDescriptor(
|
||||
name="left_expression",
|
||||
full_name="capnp.benchmark.protobuf.Expression.left_expression",
|
||||
index=2,
|
||||
number=3,
|
||||
type=11,
|
||||
cpp_type=10,
|
||||
label=1,
|
||||
has_default_value=False,
|
||||
default_value=None,
|
||||
message_type=None,
|
||||
enum_type=None,
|
||||
containing_type=None,
|
||||
is_extension=False,
|
||||
extension_scope=None,
|
||||
options=None,
|
||||
),
|
||||
_descriptor.FieldDescriptor(
|
||||
name="right_value",
|
||||
full_name="capnp.benchmark.protobuf.Expression.right_value",
|
||||
index=3,
|
||||
number=4,
|
||||
type=5,
|
||||
cpp_type=1,
|
||||
label=1,
|
||||
has_default_value=False,
|
||||
default_value=0,
|
||||
message_type=None,
|
||||
enum_type=None,
|
||||
containing_type=None,
|
||||
is_extension=False,
|
||||
extension_scope=None,
|
||||
options=None,
|
||||
),
|
||||
_descriptor.FieldDescriptor(
|
||||
name="right_expression",
|
||||
full_name="capnp.benchmark.protobuf.Expression.right_expression",
|
||||
index=4,
|
||||
number=5,
|
||||
type=11,
|
||||
cpp_type=10,
|
||||
label=1,
|
||||
has_default_value=False,
|
||||
default_value=None,
|
||||
message_type=None,
|
||||
enum_type=None,
|
||||
containing_type=None,
|
||||
is_extension=False,
|
||||
extension_scope=None,
|
||||
options=None,
|
||||
),
|
||||
],
|
||||
extensions=[],
|
||||
nested_types=[],
|
||||
enum_types=[],
|
||||
options=None,
|
||||
is_extendable=False,
|
||||
syntax="proto2",
|
||||
extension_ranges=[],
|
||||
oneofs=[],
|
||||
serialized_start=41,
|
||||
serialized_end=270,
|
||||
)
|
||||
|
||||
|
||||
_EVALUATIONRESULT = _descriptor.Descriptor(
|
||||
name='EvaluationResult',
|
||||
full_name='capnp.benchmark.protobuf.EvaluationResult',
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
containing_type=None,
|
||||
fields=[
|
||||
_descriptor.FieldDescriptor(
|
||||
name='value', full_name='capnp.benchmark.protobuf.EvaluationResult.value', index=0,
|
||||
number=1, type=17, cpp_type=1, label=2,
|
||||
has_default_value=False, default_value=0,
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
options=None),
|
||||
],
|
||||
extensions=[
|
||||
],
|
||||
nested_types=[],
|
||||
enum_types=[
|
||||
],
|
||||
options=None,
|
||||
is_extendable=False,
|
||||
syntax='proto2',
|
||||
extension_ranges=[],
|
||||
oneofs=[
|
||||
],
|
||||
serialized_start=272,
|
||||
serialized_end=305,
|
||||
name="EvaluationResult",
|
||||
full_name="capnp.benchmark.protobuf.EvaluationResult",
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
containing_type=None,
|
||||
fields=[
|
||||
_descriptor.FieldDescriptor(
|
||||
name="value",
|
||||
full_name="capnp.benchmark.protobuf.EvaluationResult.value",
|
||||
index=0,
|
||||
number=1,
|
||||
type=17,
|
||||
cpp_type=1,
|
||||
label=2,
|
||||
has_default_value=False,
|
||||
default_value=0,
|
||||
message_type=None,
|
||||
enum_type=None,
|
||||
containing_type=None,
|
||||
is_extension=False,
|
||||
extension_scope=None,
|
||||
options=None,
|
||||
),
|
||||
],
|
||||
extensions=[],
|
||||
nested_types=[],
|
||||
enum_types=[],
|
||||
options=None,
|
||||
is_extendable=False,
|
||||
syntax="proto2",
|
||||
extension_ranges=[],
|
||||
oneofs=[],
|
||||
serialized_start=272,
|
||||
serialized_end=305,
|
||||
)
|
||||
|
||||
_EXPRESSION.fields_by_name['op'].enum_type = _OPERATION
|
||||
_EXPRESSION.fields_by_name['left_expression'].message_type = _EXPRESSION
|
||||
_EXPRESSION.fields_by_name['right_expression'].message_type = _EXPRESSION
|
||||
DESCRIPTOR.message_types_by_name['Expression'] = _EXPRESSION
|
||||
DESCRIPTOR.message_types_by_name['EvaluationResult'] = _EVALUATIONRESULT
|
||||
DESCRIPTOR.enum_types_by_name['Operation'] = _OPERATION
|
||||
_EXPRESSION.fields_by_name["op"].enum_type = _OPERATION
|
||||
_EXPRESSION.fields_by_name["left_expression"].message_type = _EXPRESSION
|
||||
_EXPRESSION.fields_by_name["right_expression"].message_type = _EXPRESSION
|
||||
DESCRIPTOR.message_types_by_name["Expression"] = _EXPRESSION
|
||||
DESCRIPTOR.message_types_by_name["EvaluationResult"] = _EVALUATIONRESULT
|
||||
DESCRIPTOR.enum_types_by_name["Operation"] = _OPERATION
|
||||
_sym_db.RegisterFileDescriptor(DESCRIPTOR)
|
||||
|
||||
Expression = _reflection.GeneratedProtocolMessageType('Expression', (_message.Message,), dict(
|
||||
DESCRIPTOR = _EXPRESSION,
|
||||
__module__ = 'eval_pb2'
|
||||
# @@protoc_insertion_point(class_scope:capnp.benchmark.protobuf.Expression)
|
||||
))
|
||||
Expression = _reflection.GeneratedProtocolMessageType(
|
||||
"Expression",
|
||||
(_message.Message,),
|
||||
dict(
|
||||
DESCRIPTOR=_EXPRESSION,
|
||||
__module__="eval_pb2"
|
||||
# @@protoc_insertion_point(class_scope:capnp.benchmark.protobuf.Expression)
|
||||
),
|
||||
)
|
||||
_sym_db.RegisterMessage(Expression)
|
||||
|
||||
EvaluationResult = _reflection.GeneratedProtocolMessageType('EvaluationResult', (_message.Message,), dict(
|
||||
DESCRIPTOR = _EVALUATIONRESULT,
|
||||
__module__ = 'eval_pb2'
|
||||
# @@protoc_insertion_point(class_scope:capnp.benchmark.protobuf.EvaluationResult)
|
||||
))
|
||||
EvaluationResult = _reflection.GeneratedProtocolMessageType(
|
||||
"EvaluationResult",
|
||||
(_message.Message,),
|
||||
dict(
|
||||
DESCRIPTOR=_EVALUATIONRESULT,
|
||||
__module__="eval_pb2"
|
||||
# @@protoc_insertion_point(class_scope:capnp.benchmark.protobuf.EvaluationResult)
|
||||
),
|
||||
)
|
||||
_sym_db.RegisterMessage(EvaluationResult)
|
||||
|
||||
|
||||
|
||||
@@ -4,15 +4,11 @@ from common import rand_int, rand_double, rand_bool, from_bytes_helper
|
||||
from random import choice
|
||||
import eval_pb2
|
||||
|
||||
MAX_INT = 2**31 - 1
|
||||
MIN_INT = -(2**31)
|
||||
MAX_INT = 2 ** 31 - 1
|
||||
MIN_INT = -(2 ** 31)
|
||||
|
||||
OPERATIONS = ["add", "subtract", "multiply", "divide", "modulus"]
|
||||
|
||||
OPERATIONS = [
|
||||
"add",
|
||||
"subtract",
|
||||
"multiply",
|
||||
"divide",
|
||||
"modulus"]
|
||||
|
||||
def clamp(res):
|
||||
if res > MAX_INT:
|
||||
@@ -22,6 +18,7 @@ def clamp(res):
|
||||
else:
|
||||
return res
|
||||
|
||||
|
||||
def div(a, b):
|
||||
if b == 0:
|
||||
return MAX_INT
|
||||
@@ -30,6 +27,7 @@ def div(a, b):
|
||||
|
||||
return a // b
|
||||
|
||||
|
||||
def mod(a, b):
|
||||
if b == 0:
|
||||
return MAX_INT
|
||||
@@ -38,6 +36,7 @@ def mod(a, b):
|
||||
|
||||
return a % b
|
||||
|
||||
|
||||
def make_expression(exp, depth):
|
||||
exp.op = rand_int(len(OPERATIONS))
|
||||
|
||||
@@ -45,13 +44,13 @@ def make_expression(exp, depth):
|
||||
left = rand_int(128) + 1
|
||||
exp.left_value = left
|
||||
else:
|
||||
left = make_expression(exp.left_expression, depth+1)
|
||||
left = make_expression(exp.left_expression, depth + 1)
|
||||
|
||||
if rand_int(8) < depth:
|
||||
right = rand_int(128) + 1
|
||||
exp.right_value = right
|
||||
else:
|
||||
right = make_expression(exp.right_expression, depth+1)
|
||||
right = make_expression(exp.right_expression, depth + 1)
|
||||
|
||||
op = exp.op
|
||||
if op == 0:
|
||||
@@ -66,21 +65,21 @@ def make_expression(exp, depth):
|
||||
return mod(left, right)
|
||||
raise RuntimeError("op wasn't a valid value: " + str(op))
|
||||
|
||||
|
||||
def evaluate_expression(exp):
|
||||
left = 0
|
||||
right = 0
|
||||
|
||||
if exp.HasField('left_value'):
|
||||
if exp.HasField("left_value"):
|
||||
left = exp.left_value
|
||||
else:
|
||||
left = evaluate_expression(exp.left_expression)
|
||||
|
||||
if exp.HasField('right_value'):
|
||||
if exp.HasField("right_value"):
|
||||
right = exp.right_value
|
||||
else:
|
||||
right = evaluate_expression(exp.right_expression)
|
||||
|
||||
|
||||
op = exp.op
|
||||
if op == 0:
|
||||
return clamp(left + right)
|
||||
@@ -94,6 +93,7 @@ def evaluate_expression(exp):
|
||||
return mod(left, right)
|
||||
raise RuntimeError("op wasn't a valid value: " + str(op))
|
||||
|
||||
|
||||
class Benchmark:
|
||||
def __init__(self, compression):
|
||||
self.Request = eval_pb2.Expression
|
||||
|
||||
@@ -5,15 +5,11 @@ import eval_capnp
|
||||
from common import rand_int, rand_double, rand_bool
|
||||
from random import choice
|
||||
|
||||
MAX_INT = 2**31 - 1
|
||||
MIN_INT = -(2**31)
|
||||
MAX_INT = 2 ** 31 - 1
|
||||
MIN_INT = -(2 ** 31)
|
||||
|
||||
OPERATIONS = ["add", "subtract", "multiply", "divide", "modulus"]
|
||||
|
||||
OPERATIONS = [
|
||||
"add",
|
||||
"subtract",
|
||||
"multiply",
|
||||
"divide",
|
||||
"modulus"]
|
||||
|
||||
def clamp(res):
|
||||
if res > MAX_INT:
|
||||
@@ -23,6 +19,7 @@ def clamp(res):
|
||||
else:
|
||||
return res
|
||||
|
||||
|
||||
def div(a, b):
|
||||
if b == 0:
|
||||
return MAX_INT
|
||||
@@ -31,6 +28,7 @@ def div(a, b):
|
||||
|
||||
return a // b
|
||||
|
||||
|
||||
def mod(a, b):
|
||||
if b == 0:
|
||||
return MAX_INT
|
||||
@@ -39,6 +37,7 @@ def mod(a, b):
|
||||
|
||||
return a % b
|
||||
|
||||
|
||||
def make_expression(exp, depth):
|
||||
exp.op = choice(OPERATIONS)
|
||||
|
||||
@@ -46,62 +45,63 @@ def make_expression(exp, depth):
|
||||
left = rand_int(128) + 1
|
||||
exp.left.value = left
|
||||
else:
|
||||
left = make_expression(exp.left.init('expression'), depth+1)
|
||||
left = make_expression(exp.left.init("expression"), depth + 1)
|
||||
|
||||
if rand_int(8) < depth:
|
||||
right = rand_int(128) + 1
|
||||
exp.right.value = right
|
||||
else:
|
||||
right = make_expression(exp.right.init('expression'), depth+1)
|
||||
right = make_expression(exp.right.init("expression"), depth + 1)
|
||||
|
||||
op = exp.op
|
||||
if op == 'add':
|
||||
if op == "add":
|
||||
return clamp(left + right)
|
||||
elif op == 'subtract':
|
||||
elif op == "subtract":
|
||||
return clamp(left - right)
|
||||
elif op == 'multiply':
|
||||
elif op == "multiply":
|
||||
return clamp(left * right)
|
||||
elif op == 'divide':
|
||||
elif op == "divide":
|
||||
return div(left, right)
|
||||
elif op == 'modulus':
|
||||
elif op == "modulus":
|
||||
return mod(left, right)
|
||||
raise RuntimeError("op wasn't a valid value: " + str(op))
|
||||
|
||||
|
||||
def evaluate_expression(exp):
|
||||
left = 0
|
||||
right = 0
|
||||
|
||||
which = exp.left.which()
|
||||
if which == 'value':
|
||||
if which == "value":
|
||||
left = exp.left.value
|
||||
elif which == 'expression':
|
||||
elif which == "expression":
|
||||
left = evaluate_expression(exp.left.expression)
|
||||
|
||||
which = exp.right.which()
|
||||
if which == 'value':
|
||||
if which == "value":
|
||||
right = exp.right.value
|
||||
elif which == 'expression':
|
||||
elif which == "expression":
|
||||
right = evaluate_expression(exp.right.expression)
|
||||
|
||||
|
||||
op = exp.op
|
||||
if op == 'add':
|
||||
if op == "add":
|
||||
return clamp(left + right)
|
||||
elif op == 'subtract':
|
||||
elif op == "subtract":
|
||||
return clamp(left - right)
|
||||
elif op == 'multiply':
|
||||
elif op == "multiply":
|
||||
return clamp(left * right)
|
||||
elif op == 'divide':
|
||||
elif op == "divide":
|
||||
return div(left, right)
|
||||
elif op == 'modulus':
|
||||
elif op == "modulus":
|
||||
return mod(left, right)
|
||||
raise RuntimeError("op wasn't a valid value: " + str(op))
|
||||
|
||||
|
||||
class Benchmark:
|
||||
def __init__(self, compression):
|
||||
self.Request = eval_capnp.Expression.new_message
|
||||
self.Response = eval_capnp.EvaluationResult.new_message
|
||||
if compression == 'packed':
|
||||
if compression == "packed":
|
||||
self.from_bytes_request = eval_capnp.Expression.from_bytes_packed
|
||||
self.from_bytes_response = eval_capnp.EvaluationResult.from_bytes_packed
|
||||
self.to_bytes = lambda x: x.to_bytes_packed()
|
||||
@@ -117,4 +117,4 @@ class Benchmark:
|
||||
response.value = evaluate_expression(request)
|
||||
|
||||
def check(self, response, expected):
|
||||
return response.value == expected
|
||||
return response.value == expected
|
||||
|
||||
Reference in New Issue
Block a user