test/performance/suites/marshalling.rb in newrelic_rpm-3.7.1.188 vs test/performance/suites/marshalling.rb in newrelic_rpm-3.7.2.190.beta

- old
+ new

@@ -18,16 +18,92 @@ marshaller.dump(@tt_payload) end end end + def test_json_marshalling_binary_strings(timer) + marshaller = NewRelic::Agent::NewRelicService::JsonMarshaller.new + convert_strings_to_binary(@payload) + convert_strings_to_binary(@tt_payload) + timer.measure do + (iterations / 100).times do + marshaller.dump(@payload) + marshaller.dump(@tt_payload) + end + end + end + + def test_json_marshalling_utf16_strings(timer) + marshaller = NewRelic::Agent::NewRelicService::JsonMarshaller.new + convert_strings_to_utf16(@payload) + convert_strings_to_utf16(@tt_payload) + timer.measure do + (iterations / 100).times do + marshaller.dump(@payload) + marshaller.dump(@tt_payload) + end + end + end + + def test_json_marshalling_latin1_strings(timer) + marshaller = NewRelic::Agent::NewRelicService::JsonMarshaller.new + convert_strings_to_latin1(@payload) + convert_strings_to_latin1(@tt_payload) + timer.measure do + (iterations / 100).times do + marshaller.dump(@payload) + marshaller.dump(@tt_payload) + end + end + end + def test_basic_marshalling_pruby(timer) marshaller = NewRelic::Agent::NewRelicService::PrubyMarshaller.new timer.measure do (iterations / 100).times do marshaller.dump(@payload) marshaller.dump(@tt_payload) end + end + end + + # Skips Strings used as Hash keys, since they are frozen + def each_string(object, &blk) + case object + when String + blk.call(object) + when Array + object.map! { |x| each_string(x, &blk) } + when Hash + object.values.each do |v| + each_string(v, &blk) + end + end + end + + BYTE_ALPHABET = (0..255).to_a.freeze + + def generate_random_string(length) + bytes = [] + length.times { bytes << BYTE_ALPHABET.sample } + bytes.pack("C*") + end + + def convert_strings_to_binary(object) + each_string(object) do |s| + s.replace(generate_random_string(s.bytesize)) + end + end + + def convert_strings_to_utf16(object) + each_string(object) do |s| + s.encode!('UTF-16') + end + end + + def convert_strings_to_latin1(object) + each_string(object) do |s| + s.replace(generate_random_string(s.bytesize)).force_encoding('ISO-8859-1') end end # Build an object graph that approximates a transaction trace in structure def build_transaction_trace_payload(depth=6)