Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpr5/532263 to your computer and use it in GitHub Desktop.
Save jpr5/532263 to your computer and use it in GitHub Desktop.
# With Enum
creating 20 models took: 0.830000 0.010000 0.840000 ( 0.833432)
user system total real
Enum: 0.080000 0.000000 0.080000 ( 0.082003)
Decimal: 0.050000 0.000000 0.050000 ( 0.050160)
DateTime: 0.040000 0.000000 0.040000 ( 0.046490)
String: 0.080000 0.000000 0.080000 ( 0.077332)
Integer: 0.030000 0.000000 0.030000 ( 0.033848)
Boolean: 0.060000 0.000000 0.060000 ( 0.052100)
IPAddress: 0.080000 0.000000 0.080000 ( 0.085706)
Float: 0.030000 0.000000 0.030000 ( 0.033280)
# Without Enum
creating 20 models took: 0.810000 0.010000 0.820000 ( 0.817266)
user system total real
Decimal: 0.070000 0.000000 0.070000 ( 0.066363)
DateTime: 0.030000 0.000000 0.030000 ( 0.034056)
String: 0.050000 0.000000 0.050000 ( 0.042935)
Integer: 0.060000 0.000000 0.060000 ( 0.062835)
Boolean: 0.040000 0.000000 0.040000 ( 0.037585)
IPAddress: 0.030000 0.000000 0.030000 ( 0.038801)
Float: 0.070000 0.000000 0.070000 ( 0.064341)
# With Enum:
creating 20 models took: 1.140000 0.010000 1.150000 ( 1.143344)
user system total real
Enum: 4.110000 0.010000 4.120000 ( 4.129154)
Decimal: 8.190000 0.080000 8.270000 ( 8.258901)
DateTime: 0.240000 0.000000 0.240000 ( 0.246580)
String: 0.280000 0.000000 0.280000 ( 0.282992)
Integer: 0.270000 0.000000 0.270000 ( 0.270241)
Boolean: 8.170000 0.010000 8.180000 ( 8.168547)
IPAddress: 8.220000 0.000000 8.220000 ( 8.226776)
Float: 0.280000 0.000000 0.280000 ( 0.275023)
# Without Enum:
creating 20 models took: 1.110000 0.020000 1.130000 ( 1.120532)
user system total real
Decimal: 0.040000 0.000000 0.040000 ( 0.047718)
DateTime: 0.070000 0.000000 0.070000 ( 0.071919)
String: 0.050000 0.000000 0.050000 ( 0.052300)
Integer: 0.070000 0.000000 0.070000 ( 0.072988)
Boolean: 0.050000 0.000000 0.050000 ( 0.050140)
IPAddress: 0.080000 0.000000 0.080000 ( 0.085798)
Float: 0.040000 0.000000 0.040000 ( 0.042051)
# With Enum
creating 20 models took: 0.910000 0.010000 0.920000 ( 0.916317)
user system total real
Enum: 0.350000 0.000000 0.350000 ( 0.355736)
Decimal: 0.580000 0.010000 0.590000 ( 0.584085)
DateTime: 0.050000 0.000000 0.050000 ( 0.051884)
String: 0.100000 0.010000 0.110000 ( 0.101625)
Integer: 0.050000 0.000000 0.050000 ( 0.052278)
Boolean: 0.590000 0.000000 0.590000 ( 0.594667)
IPAddress: 0.550000 0.010000 0.560000 ( 0.559550)
Float: 0.090000 0.000000 0.090000 ( 0.087780)
# Without Enum
creating 20 models took: 0.920000 0.020000 0.940000 ( 0.931759)
user system total real
Decimal: 0.070000 0.000000 0.070000 ( 0.071321)
DateTime: 0.030000 0.000000 0.030000 ( 0.036346)
String: 0.050000 0.000000 0.050000 ( 0.046200)
Integer: 0.070000 0.000000 0.070000 ( 0.067341)
Boolean: 0.040000 0.000000 0.040000 ( 0.040310)
IPAddress: 0.070000 0.000000 0.070000 ( 0.076454)
Float: 0.040000 0.000000 0.040000 ( 0.036149)
#!/usr/bin/ruby -rubygems
# Gems pegged against GIT
require 'dm-core'
require 'dm-migrations' # 69551c9
# Gems pegged at 1.0.0
require 'dm-types'
require 'dm-timestamps'
require 'dm-validations'
require 'dm-serializer'
require 'dm-aggregates'
require 'dm-ar-finders'
require 'dm-transactions'
# + do_mysql 0.9.12
require 'benchmark'
num_classes = 20
num_attrs = 10
foo = Benchmark.measure {
num_classes.times do |n|
Class.new.class_eval do
include ::DataMapper::Resource
num_attrs.times do |x|
property "str#{x}".to_sym, const_get("String")
end
num_attrs.times do |x|
property "num#{x}".to_sym, const_get("Integer")
end
num_attrs.times do |x|
property "bool#{x}".to_sym, const_get("Boolean")
end
num_attrs.times do |x|
property "decimal#{x}".to_sym, const_get("Decimal"), :scale => 2, :precision => 6
end
num_attrs.times do |x|
property "float#{x}".to_sym, const_get("Float")
end
end
end
}
puts "creating #{num_classes} models took: #{foo}"
num_classes = 1
num_attrs = 50
Benchmark.bm(15) do |bm|
bm.report("Enum:") do
num_classes.times do |n|
Class.new.class_eval do
include ::DataMapper::Resource
num_attrs.times do |x|
# puts x <- run this to see how it slows down - pretty crazy!
property "Enum#{x}".to_sym, const_get("Enum")[:disabled, :active, :complete], :default => :disabled
end
end
end
end
bm.report("Decimal:") do
num_classes.times do |n|
Class.new.class_eval do
include ::DataMapper::Resource
num_attrs.times do |x|
property "Decimal#{x}".to_sym, const_get("Decimal"), :scale => 2, :precision => 6
end
end
end
end
%w[ DateTime String Integer Boolean IPAddress Float ].each do |prop_type|
bm.report("#{prop_type.to_s}:") do
num_classes.times do |n|
Class.new.class_eval do
include ::DataMapper::Resource
num_attrs.times do |x|
property "#{prop_type.to_s}#{x}".to_sym, const_get(prop_type)
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment