<commit_before># frozen_string_literal: true
require_relative "./support"

def panko_type_convert(type_klass, from, to)
  converter = type_klass.new
  assert "#{type_klass.name}", Panko::_type_cast(converter, from), to

  Benchmark.ams("#{type_klass.name}_TypeCast") do
    Panko::_type_cast(converter, from)
  end

  Benchmark.ams("#{type_klass.name}_NoTypeCast") do
    Panko::_type_cast(converter, to)
  end
end


def utc_panko_time
	date = DateTime.new(2017, 3, 4, 12, 45, 23)
	tz = ActiveSupport::TimeZone.new("UTC")
	from = date.in_time_zone(tz).iso8601

  type = ActiveRecord::ConnectionAdapters::PostgreSQL::OID::DateTime.new
  converter = ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter.new(type)

  to = Panko::_type_cast(converter, from)

  Benchmark.ams("#{tz}_#{type.class.name}_TypeCast") do
    Panko::_type_cast(converter, from)
  end

  Benchmark.ams("#{tz}_#{type.class.name}_NoTypeCast") do
    Panko::_type_cast(converter, to)
  end
end

def db_panko_time
  type = ActiveRecord::ConnectionAdapters::PostgreSQL::OID::DateTime.new
  converter = ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter.new(type)

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

  Benchmark.ams("Panko_Time_TypeCast") do
		Panko::_type_cast(converter, from)
  end
end

db_panko_time
utc_panko_time

exit

panko_type_convert ActiveRecord::Type::String, 1, "1"<commit_msg>Panko Type Casting: remove `exit` statement<commit_after># frozen_string_literal: true
require_relative "./support"

def panko_type_convert(type_klass, from, to)
  converter = type_klass.new
  assert "#{type_klass.name}", Panko::_type_cast(converter, from), to

  Benchmark.ams("#{type_klass.name}_TypeCast") do
    Panko::_type_cast(converter, from)
  end

  Benchmark.ams("#{type_klass.name}_NoTypeCast") do
    Panko::_type_cast(converter, to)
  end
end


def utc_panko_time
	date = DateTime.new(2017, 3, 4, 12, 45, 23)
	tz = ActiveSupport::TimeZone.new("UTC")
	from = date.in_time_zone(tz).iso8601

  type = ActiveRecord::ConnectionAdapters::PostgreSQL::OID::DateTime.new
  converter = ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter.new(type)

  to = Panko::_type_cast(converter, from)

  Benchmark.ams("#{tz}_#{type.class.name}_TypeCast") do
    Panko::_type_cast(converter, from)
  end

  Benchmark.ams("#{tz}_#{type.class.name}_NoTypeCast") do
    Panko::_type_cast(converter, to)
  end
end

def db_panko_time
  type = ActiveRecord::ConnectionAdapters::PostgreSQL::OID::DateTime.new
  converter = ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter.new(type)

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

  Benchmark.ams("Panko_Time_TypeCast") do
		Panko::_type_cast(converter, from)
  end
end

panko_type_convert ActiveRecord::Type::String, 1, "1"
{'fraction_non_alphanumeric': 0.13460157932519742, 'fraction_numerical': 0.027279253409906678, 'mean_word_length': 6.432, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4491560', 'n_tokens_mistral': 1099, 'n_tokens_neox': 1044, 'n_words': 161}