コード例 #1
0
def run_coder_benchmarks(num_runs,
                         input_size,
                         seed,
                         verbose,
                         filter_regex='.*'):
    random.seed(seed)

    # TODO(BEAM-4441): Pick coders using type hints, for example:
    # tuple_coder = typecoders.registry.get_coder(typing.Tuple[int, ...])
    benchmarks = [
        coder_benchmark_factory(coders.FastPrimitivesCoder(), small_int),
        coder_benchmark_factory(coders.FastPrimitivesCoder(), large_int),
        coder_benchmark_factory(coders.FastPrimitivesCoder(), small_string),
        coder_benchmark_factory(coders.FastPrimitivesCoder(), large_string),
        coder_benchmark_factory(coders.FastPrimitivesCoder(), small_list),
        coder_benchmark_factory(
            coders.IterableCoder(coders.FastPrimitivesCoder()), small_list),
        coder_benchmark_factory(coders.FastPrimitivesCoder(), large_list),
        coder_benchmark_factory(
            coders.IterableCoder(coders.FastPrimitivesCoder()), large_list),
        coder_benchmark_factory(
            coders.IterableCoder(coders.FastPrimitivesCoder()),
            large_iterable),
        coder_benchmark_factory(coders.FastPrimitivesCoder(), small_tuple),
        coder_benchmark_factory(coders.FastPrimitivesCoder(), large_tuple),
        coder_benchmark_factory(coders.FastPrimitivesCoder(), small_dict),
        coder_benchmark_factory(coders.FastPrimitivesCoder(), large_dict),
        coder_benchmark_factory(coders.ProtoCoder(test_message.MessageWithMap),
                                small_message_with_map),
        coder_benchmark_factory(coders.ProtoCoder(test_message.MessageWithMap),
                                large_message_with_map),
        coder_benchmark_factory(
            coders.DeterministicProtoCoder(test_message.MessageWithMap),
            small_message_with_map),
        coder_benchmark_factory(
            coders.DeterministicProtoCoder(test_message.MessageWithMap),
            large_message_with_map),
        coder_benchmark_factory(
            coders.WindowedValueCoder(coders.FastPrimitivesCoder()),
            wv_with_one_window),
        coder_benchmark_factory(
            coders.WindowedValueCoder(coders.FastPrimitivesCoder(),
                                      coders.IntervalWindowCoder()),
            wv_with_multiple_windows),
        coder_benchmark_factory(
            coders.WindowedValueCoder(coders.FastPrimitivesCoder(),
                                      coders.GlobalWindowCoder()),
            globally_windowed_value),
        coder_benchmark_factory(
            coders.LengthPrefixCoder(coders.FastPrimitivesCoder()), small_int)
    ]

    suite = [
        utils.BenchmarkConfig(b, input_size, num_runs) for b in benchmarks
        if re.search(filter_regex, b.__name__, flags=re.I)
    ]
    utils.run_benchmarks(suite, verbose=verbose)
コード例 #2
0
ファイル: coders_test.py プロジェクト: horvathaa/beamTest
 def test_proto_coder(self):
     ma = test_message.MessageA()
     mb = ma.field2.add()
     mb.field1 = True
     ma.field1 = u'hello world'
     expected_coder = coders.ProtoCoder(ma.__class__)
     real_coder = coders_registry.get_coder(ma.__class__)
     self.assertEqual(expected_coder, real_coder)
     self.assertEqual(real_coder.encode(ma), expected_coder.encode(ma))
     self.assertEqual(ma, real_coder.decode(real_coder.encode(ma)))
コード例 #3
0
    def test_proto_coder(self):
        # For instructions on how these test proto message were generated,
        # see coders_test.py
        ma = test_message.MessageA()
        mab = ma.field2.add()
        mab.field1 = True
        ma.field1 = u'hello world'

        mb = test_message.MessageA()
        mb.field1 = u'beam'

        proto_coder = coders.ProtoCoder(ma.__class__)
        self.check_coder(proto_coder, ma)
        self.check_coder(coders.TupleCoder((proto_coder, coders.BytesCoder())),
                         (ma, 'a'), (mb, 'b'))