def _benchmark_READ_SINGLE_ROW(model_class): with create_row(model_class) as (row, key): def fn(): model_class.get([key]) seconds = benchmark_fn(fn, CRUD_ITERATIONS) return CrudTestGroups.READ_SINGLE_ROW, seconds, CRUD_ITERATIONS, 1
def _benchmark_MODEL_TO_PROTOBUF_STRING(model_class): with create_row(model_class) as (row, key): def fn(): entity_proto = row.convert_to_proto() entity_proto.SerializeToString() seconds = benchmark_fn(fn, SERIALIZATION_ITERATIONS) return SerializationTestGroups.MODEL_TO_PROTOBUF_STRING, seconds, SERIALIZATION_ITERATIONS, 1
def _benchmark_UPDATE_SINGLE_ROW(model_class): with create_row(model_class) as (row, key): def fn(): for property in row._properties.keys(): setattr(row, property, str(uuid.uuid4())) model_class.put([row]) seconds = benchmark_fn(fn, CRUD_ITERATIONS) return CrudTestGroups.UPDATE_SINGLE_ROW, seconds, CRUD_ITERATIONS, 1
def _benchmark_LAZY_READ_SINGLE_ROW(model_class): with create_row(model_class) as (row, key): if issubclass(model_class, ndb.Model): key = key.to_old_key() def fn(): model_class.get_lazy([key]) seconds = benchmark_fn(fn, CRUD_ITERATIONS) return CrudTestGroups.LAZY_READ_SINGLE_ROW, seconds, CRUD_ITERATIONS, 1
def _benchmark_PROTOBUF_STRING_TO_ENTITY_PROTO(model_class): with create_row(model_class) as (row, key): entity_proto = row.convert_to_proto() serialized = entity_proto.SerializeToString() def fn(): entity_proto = entity_pb.EntityProto(serialized) datastore.Entity.FromPb(entity_proto) seconds = benchmark_fn(fn, SERIALIZATION_ITERATIONS) return SerializationTestGroups.PROTOBUF_STRING_TO_ENTITY_PROTO, seconds, SERIALIZATION_ITERATIONS, 1
def _benchmark_SINGLE_LAZY_PROPERTY_ACCESS_TIMES_PROTOBUF_TO_MODEL( model_class): with create_row(model_class) as (row, key): entity_proto = row.convert_to_proto() serialized = entity_proto.SerializeToString() def fn(): entity_proto = entity_pb.EntityProto(serialized) deserialized = datastore_lazy.LazyEntity(entity_proto) len(deserialized.prop_0) seconds = benchmark_fn(fn, SERIALIZATION_ITERATIONS) return SerializationTestGroups.SINGLE_LAZY_PROPERTY_ACCESS_TIMES_PROTOBUF_TO_MODEL, seconds, SERIALIZATION_ITERATIONS, 1
def _benchmark_ENTITY_TO_PROTOBUF_STRING(model_class): with create_row(model_class) as (row, key): try: entity = row.convert_to_entity() except NotImplementedError: return SerializationTestGroups.ENTITY_TO_PROTOBUF_STRING, None, None, None def fn(): entity_proto = entity.ToPb() entity_proto.SerializeToString() seconds = benchmark_fn(fn, SERIALIZATION_ITERATIONS) return SerializationTestGroups.ENTITY_TO_PROTOBUF_STRING, seconds, SERIALIZATION_ITERATIONS, 1
def _benchmark_MULTI_PROPERTY_ACCESS_TIMES_PROTOBUF_TO_MODEL(model_class): with create_row(model_class) as (row, key): entity_proto = row.convert_to_proto() serialized = entity_proto.SerializeToString() def fn(): # entity_proto = entity_pb.EntityProto(serialized) # entity = datastore.Entity.FromPb(entity_proto) # deserialized = model_class.convert_from_entity(entity) deserialized = model_class.convert_from_binary(serialized) len(deserialized.prop_0) len(deserialized.prop_1) len(deserialized.prop_2) len(deserialized.prop_3) len(deserialized.prop_4) len(deserialized.prop_5) len(deserialized.prop_6) len(deserialized.prop_7) len(deserialized.prop_8) len(deserialized.prop_9) seconds = benchmark_fn(fn, SERIALIZATION_ITERATIONS) return SerializationTestGroups.MULTI_PROPERTY_ACCESS_TIMES_PROTOBUF_TO_MODEL, seconds, SERIALIZATION_ITERATIONS, 1