Skip to content

[Experiment] Re-write in Ruby #175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 42 additions & 10 deletions benchmarks/type_casts/bm_panko.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,39 @@

require_relative "support"

class NoopWriter
attr_reader :value
def push_value(value, key)
@value = value
nil
end

def push_json(value, key)
nil
end
end

class Attribute
attr_reader :name_for_serialization, :type

def initialize(name_for_serialization:, type:)
@name_for_serialization = name_for_serialization
@type = type
end
end

def panko_type_convert(type_klass, from, to)
converter = type_klass.new
assert type_klass.name.to_s, Panko._type_cast(converter, from), to

writer = NoopWriter.new
attribute = Attribute.new(name_for_serialization: "key", type: converter)

Benchmark.run("#{type_klass.name}_TypeCast") do
Panko._type_cast(converter, from)
Panko::Impl::AttributesWriter::ActiveRecord::ValuesWriter.write(writer, attribute, from)
end

Benchmark.run("#{type_klass.name}_NoTypeCast") do
Panko._type_cast(converter, to)
Panko::Impl::AttributesWriter::ActiveRecord::ValuesWriter.write(writer, attribute, to)
end
end

Expand All @@ -23,14 +46,19 @@ def utc_panko_time
type = ActiveRecord::ConnectionAdapters::PostgreSQL::OID::DateTime.new
converter = ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter.new(type)

to = Panko._type_cast(converter, from)
writer = NoopWriter.new
attribute = Attribute.new(name_for_serialization: "key", type: converter)

# get the to value
Panko::Impl::AttributesWriter::ActiveRecord::ValuesWriter.write(writer, attribute, from)
to = writer.value

Benchmark.run("#{tz}_#{type.class.name}_TypeCast") do
Panko._type_cast(converter, from)
Panko::Impl::AttributesWriter::ActiveRecord::ValuesWriter.write(writer, attribute, from)
end

Benchmark.run("#{tz}_#{type.class.name}_NoTypeCast") do
Panko._type_cast(converter, to)
Panko::Impl::AttributesWriter::ActiveRecord::ValuesWriter.write(writer, attribute, to)
end
end

Expand All @@ -40,18 +68,24 @@ def db_panko_time

from = "2017-07-10 09:26:40.937392"

writer = NoopWriter.new
attribute = Attribute.new(name_for_serialization: "key", type: converter)

Benchmark.run("Panko_Time_TypeCast") do
Panko._type_cast(converter, from)
Panko::Impl::AttributesWriter::ActiveRecord::ValuesWriter.write(writer, attribute, from)
end
end

panko_type_convert ActiveRecord::Type::String, 1, "1"
panko_type_convert ActiveRecord::Type::Text, 1, "1"
panko_type_convert ActiveRecord::Type::Integer, "1", 1
panko_type_convert ActiveRecord::Type::Text, 1, "1"
panko_type_convert ActiveRecord::Type::Float, "1.23", 1.23
panko_type_convert ActiveRecord::Type::Boolean, "true", true
panko_type_convert ActiveRecord::Type::Boolean, "t", true

db_panko_time
utc_panko_time

if check_if_exists "ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Json"
panko_type_convert ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Json, '{"a":1}', '{"a":1}'
end
Expand All @@ -61,5 +95,3 @@ def db_panko_time
if check_if_exists "ActiveRecord::Type::Json"
panko_type_convert ActiveRecord::Type::Json, '{"a":1}', '{"a":1}'
end
db_panko_time
utc_panko_time
208 changes: 0 additions & 208 deletions ext/panko_serializer/attributes_writer/active_record.c

This file was deleted.

17 changes: 0 additions & 17 deletions ext/panko_serializer/attributes_writer/active_record.h

This file was deleted.

55 changes: 0 additions & 55 deletions ext/panko_serializer/attributes_writer/attributes_writer.c

This file was deleted.

Loading
Loading