home_run 0.9.0-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. data/CHANGELOG +3 -0
  2. data/LICENSE +19 -0
  3. data/README.rdoc +314 -0
  4. data/Rakefile +136 -0
  5. data/bench/cpu_bench.rb +279 -0
  6. data/bench/dt_garbage_bench.rb +11 -0
  7. data/bench/dt_mem_bench.rb +14 -0
  8. data/bench/garbage_bench.rb +11 -0
  9. data/bench/mem_bench.rb +14 -0
  10. data/bin/home_run +91 -0
  11. data/default.mspec +12 -0
  12. data/ext/1.8/date_ext.so +0 -0
  13. data/ext/1.9/date_ext.so +0 -0
  14. data/ext/date.rb +7 -0
  15. data/ext/date/format.rb +842 -0
  16. data/ext/date_ext.c +4548 -0
  17. data/ext/date_parser.c +367 -0
  18. data/ext/date_parser.rl +134 -0
  19. data/ext/datetime.c +2804 -0
  20. data/ext/extconf.rb +6 -0
  21. data/spec/date/accessor_spec.rb +176 -0
  22. data/spec/date/add_month_spec.rb +26 -0
  23. data/spec/date/add_spec.rb +23 -0
  24. data/spec/date/boat_spec.rb +38 -0
  25. data/spec/date/civil_spec.rb +147 -0
  26. data/spec/date/commercial_spec.rb +153 -0
  27. data/spec/date/constants_spec.rb +44 -0
  28. data/spec/date/conversions_spec.rb +246 -0
  29. data/spec/date/day_spec.rb +73 -0
  30. data/spec/date/downto_spec.rb +17 -0
  31. data/spec/date/eql_spec.rb +16 -0
  32. data/spec/date/format_spec.rb +52 -0
  33. data/spec/date/gregorian_spec.rb +52 -0
  34. data/spec/date/hash_spec.rb +11 -0
  35. data/spec/date/julian_spec.rb +129 -0
  36. data/spec/date/leap_spec.rb +19 -0
  37. data/spec/date/minus_month_spec.rb +25 -0
  38. data/spec/date/minus_spec.rb +51 -0
  39. data/spec/date/next_prev_spec.rb +108 -0
  40. data/spec/date/ordinal_spec.rb +83 -0
  41. data/spec/date/parse_spec.rb +442 -0
  42. data/spec/date/parsing_spec.rb +77 -0
  43. data/spec/date/relationship_spec.rb +28 -0
  44. data/spec/date/step_spec.rb +109 -0
  45. data/spec/date/strftime_spec.rb +223 -0
  46. data/spec/date/strptime_spec.rb +201 -0
  47. data/spec/date/succ_spec.rb +20 -0
  48. data/spec/date/today_spec.rb +15 -0
  49. data/spec/date/upto_spec.rb +17 -0
  50. data/spec/datetime/accessor_spec.rb +218 -0
  51. data/spec/datetime/add_month_spec.rb +26 -0
  52. data/spec/datetime/add_spec.rb +36 -0
  53. data/spec/datetime/boat_spec.rb +43 -0
  54. data/spec/datetime/constructor_spec.rb +142 -0
  55. data/spec/datetime/conversions_spec.rb +54 -0
  56. data/spec/datetime/day_spec.rb +73 -0
  57. data/spec/datetime/downto_spec.rb +39 -0
  58. data/spec/datetime/eql_spec.rb +17 -0
  59. data/spec/datetime/format_spec.rb +59 -0
  60. data/spec/datetime/hash_spec.rb +11 -0
  61. data/spec/datetime/leap_spec.rb +19 -0
  62. data/spec/datetime/minus_month_spec.rb +25 -0
  63. data/spec/datetime/minus_spec.rb +77 -0
  64. data/spec/datetime/next_prev_spec.rb +138 -0
  65. data/spec/datetime/now_spec.rb +18 -0
  66. data/spec/datetime/parse_spec.rb +390 -0
  67. data/spec/datetime/parsing_spec.rb +77 -0
  68. data/spec/datetime/relationship_spec.rb +28 -0
  69. data/spec/datetime/step_spec.rb +155 -0
  70. data/spec/datetime/strftime_spec.rb +118 -0
  71. data/spec/datetime/strptime_spec.rb +117 -0
  72. data/spec/datetime/succ_spec.rb +24 -0
  73. data/spec/datetime/upto_spec.rb +39 -0
  74. data/spec/spec_helper.rb +59 -0
  75. metadata +154 -0
@@ -0,0 +1,279 @@
1
+ require 'rbconfig'
2
+ $:.unshift RbConfig::CONFIG['rubylibdir']
3
+ require 'date'
4
+ require 'benchmark'
5
+
6
+ SD = Date
7
+ SDT = DateTime
8
+ Object.send(:remove_const, :Date)
9
+ Object.send(:remove_const, :DateTime)
10
+ $:.unshift(File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'ext'))
11
+ load 'ext/date.rb'
12
+ load 'ext/date/format.rb'
13
+ HRD = Date
14
+ HRDT = DateTime
15
+ NANOS_PER_SEC = 1000000000
16
+ N = 10000
17
+ FILTER = ARGV.empty? ? nil : Regexp.new(ARGV[0])
18
+
19
+ def compare(label, datetime=false, &block)
20
+ return if FILTER && label !~ FILTER
21
+ Object.send(:remove_const, :Date)
22
+ Object.send(:remove_const, :DateTime)
23
+ Object.send(:const_set, :Date, SD)
24
+ Object.send(:const_set, :DateTime, SDT)
25
+ stdlib = 0.0
26
+ stdlib_times = 0
27
+ while stdlib < 2
28
+ t = Time.now
29
+ yield(datetime ? SDT : SD)
30
+ stdlib += Time.now - t
31
+ stdlib_times += 1
32
+ end
33
+
34
+ Object.send(:remove_const, :Date)
35
+ Object.send(:remove_const, :DateTime)
36
+ Object.send(:const_set, :Date, HRD)
37
+ Object.send(:const_set, :DateTime, HRDT)
38
+ home_run = 0.0
39
+ home_run_times = 0
40
+ while home_run < 2
41
+ t = Time.now
42
+ yield(datetime ? HRDT : HRD)
43
+ home_run += Time.now - t
44
+ home_run_times += 1
45
+ end
46
+
47
+ puts sprintf('%s%s,%i,%i,%0.2f', datetime ? 'DateTime' : 'Date', label, (stdlib * NANOS_PER_SEC)/(N * stdlib_times), (home_run * NANOS_PER_SEC)/(N * home_run_times), (stdlib/stdlib_times)/(home_run/home_run_times))
48
+ end
49
+
50
+ def dt_compare(label, &block)
51
+ compare(label, true, &block)
52
+ end
53
+
54
+ n = N
55
+ puts "label,stdlib,home_run,times faster"
56
+ compare("._parse"){|dc| n.times{dc._parse('2010-12-13')}}
57
+ compare("._strptime"){|dc| n.times{dc._strptime('fri jan 5 00:00:00 2007', '%c')}}
58
+ compare(".civil"){|dc| n.times{dc.civil(2010, 1, 1)}}
59
+ compare(".commercial"){|dc| n.times{dc.commercial(2010, 1, 1)}}
60
+ compare(".gregorian_leap?"){|dc| n.times{dc.gregorian_leap?(2000)}}
61
+ compare(".jd"){|dc| n.times{dc.jd(2010)}}
62
+ compare(".julian_leap?"){|dc| n.times{dc.julian_leap?(2000)}}
63
+ compare(".new!"){|dc| n.times{dc.new!(2012)}}
64
+ compare(".ordinal"){|dc| n.times{dc.ordinal(2012, 100)}}
65
+ compare(".parse"){|dc| n.times{dc.parse('2010-12-13')}}
66
+ compare(".strptime"){|dc| n.times{dc.strptime('fri jan 5 00:00:00 2007', '%c')}}
67
+ compare(".today"){|dc| n.times{dc.today}}
68
+ compare(".valid_civil?"){|dc| n.times{dc.valid_civil?(2010, 1, 1)}}
69
+ compare(".valid_commercial?"){|dc| n.times{dc.valid_commercial?(2010, 1, 1)}}
70
+ compare(".valid_jd?"){|dc| n.times{dc.valid_jd?(2010)}}
71
+ compare(".valid_ordinal?"){|dc| n.times{dc.valid_jd?(2010, 100)}}
72
+
73
+ dt_compare("._parse"){|dc| n.times{dc._parse('2010-12-13 10:20:30-07:00')}}
74
+ dt_compare("._strptime"){|dc| n.times{dc._strptime('fri jan 5 13:43:37 2007', '%c')}}
75
+ dt_compare(".civil"){|dc| n.times{dc.civil(2010, 1, 1, 13, 43, 57)}}
76
+ dt_compare(".commercial"){|dc| n.times{dc.commercial(2010, 1, 1, 13, 43, 57)}}
77
+ dt_compare(".jd"){|dc| n.times{dc.jd(2010, 13, 43, 57)}}
78
+ dt_compare(".new!"){|dc| n.times{dc.new!(201013.3, -8/24.0)}}
79
+ dt_compare(".now"){|dc| n.times{dc.now}}
80
+ dt_compare(".ordinal"){|dc| n.times{dc.ordinal(2010, 1, 13, 43, 57)}}
81
+ dt_compare(".parse"){|dc| n.times{dc.parse('2010-12-13T13:43:57+08:00')}}
82
+ dt_compare(".strptime"){|dc| n.times{dc.strptime('fri jan 5 13:43:37 2007', '%c')}}
83
+
84
+ compare("#+"){|dc| d = dc.civil(2010, 1, 1); n.times{d + 100}}
85
+ compare("#- Integer"){|dc| d = dc.civil(2010, 1, 1); n.times{d - 100}}
86
+ compare("#- Date"){|dc| d = dc.jd(2010); d2 = dc.jd(2011); n.times{d - d2}}
87
+ compare("#- DateTime"){|dc| d = dc.jd(2010); d2 = DateTime.jd(2011); n.times{d - d2}}
88
+ compare("#<<"){|dc| d = dc.civil(2011, 7, 31); n.times{d << 17}}
89
+ compare("#>>"){|dc| d = dc.civil(2010, 1, 31); n.times{d >> 13}}
90
+ compare("#<=> Date"){|dc| d = dc.civil(2010, 1, 1); d2 = dc.civil(2010, 1, 2); n.times{d <=> d2}}
91
+ compare("#<=> DateTime"){|dc| d = dc.civil(2010, 1, 1); d2 = DateTime.civil(2010, 1, 2, 13, 14, 15); n.times{d <=> d2}}
92
+ compare("#<=> Integer"){|dc| d = dc.civil(2010, 1, 1); d2 = 2010; n.times{d <=> d2}}
93
+ compare("#=== Date"){|dc| d = dc.civil(2010, 1, 1); d2 = dc.civil(2010, 1, 2); n.times{d === d2}}
94
+ compare("#=== DateTime"){|dc| d = dc.civil(2010, 1, 1); d2 = DateTime.civil(2010, 1, 2, 13, 14, 15); n.times{d === d2}}
95
+ compare("#=== Integer"){|dc| d = dc.civil(2010, 1, 1); d2 = 2010; n.times{d === d2}}
96
+ compare("#ajd"){|dc| d = dc.jd(2010); n.times{d.ajd}}
97
+ compare("#amjd"){|dc| d = dc.jd(2010); n.times{d.amjd}}
98
+ compare("#asctime"){|dc| d = dc.civil(2010, 1, 1); n.times{d.asctime}}
99
+ compare("#cwday"){|dc| d = dc.civil(2010, 1, 1); n.times{d.cwday}}
100
+ compare("#cweek"){|dc| d = dc.civil(2010, 1, 1); n.times{d.cweek}}
101
+ compare("#cwyear"){|dc| d = dc.civil(2010, 1, 1); n.times{d.cwyear}}
102
+ compare("#day"){|dc| d = dc.civil(2010, 1, 1); n.times{d.day}}
103
+ compare("#day_fraction"){|dc| d = dc.civil(2010, 1, 1); n.times{d.day_fraction}}
104
+ compare("#downto"){|dc| d = dc.civil(2010, 1, 10); d2 = dc.civil(2010, 1, 1); n.times{d.downto(d2){}}}
105
+ compare("#eql?"){|dc| d = dc.civil(2010, 1, 1); d2 = dc.civil(2010, 1, 1); n.times{d.eql? d2}}
106
+ compare("#gregorian"){|dc| d = dc.civil(2010, 1, 1); n.times{d.gregorian}}
107
+ compare("#gregorian?"){|dc| d = dc.civil(2010, 1, 1); n.times{d.gregorian?}}
108
+ compare("#hash"){|dc| d = dc.civil(2010, 1, 1); n.times{d.hash}}
109
+ compare("#inspect"){|dc| d = dc.civil(2010, 1, 1); n.times{d.inspect}}
110
+ compare("#jd"){|dc| d = dc.jd(2010); n.times{d.jd}}
111
+ compare("#julian?"){|dc| d = dc.civil(2010, 1, 1); n.times{d.julian?}}
112
+ compare("#ld"){|dc| d = dc.civil(2010, 1, 1); n.times{d.ld}}
113
+ compare("#leap?"){|dc| d = dc.civil(2010, 1, 1); n.times{d.leap?}}
114
+ compare("#mjd"){|dc| d = dc.civil(2010, 1, 1); n.times{d.mjd}}
115
+ compare("#month"){|dc| d = dc.civil(2010, 1, 1); n.times{d.month}}
116
+ compare("#new_start"){|dc| d = dc.civil(2010, 1, 1); n.times{d.new_start 0}}
117
+ compare("#next"){|dc| d = dc.civil(2010, 1, 1); n.times{d.next}}
118
+ compare("#start"){|dc| d = dc.civil(2010, 1, 1); n.times{d.start}}
119
+ compare("#step"){|dc| d = dc.civil(2010, 1, 1); d2 = dc.civil(2010, 1, 10); n.times{d.step(d2){}}}
120
+ compare("#strftime"){|dc| d = dc.civil(2010, 1, 10); n.times{d.strftime('%+')}}
121
+ compare("#to_s"){|dc| d = dc.civil(2010, 1, 1); n.times{d.to_s}}
122
+ compare("#upto"){|dc| d = dc.civil(2010, 1, 1); d2 = dc.civil(2010, 1, 10); n.times{d.upto(d2){}}}
123
+ compare("#wday"){|dc| d = dc.civil(2010, 1, 1); n.times{d.wday}}
124
+ compare("#yday"){|dc| d = dc.civil(2010, 1, 1); n.times{d.yday}}
125
+ compare("#year"){|dc| d = dc.civil(2010, 1, 1); n.times{d.year}}
126
+
127
+ dt_compare("#+"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d + 100}}
128
+ dt_compare("#- Integer"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d - 100}}
129
+ dt_compare("#- Date"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); d2 = Date.civil(2010, 1, 2); n.times{d - d2}}
130
+ dt_compare("#- DateTime"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); d2 = dc.civil(2010, 1, 6, 21, 31, 45); n.times{d - d2}}
131
+ dt_compare("#>>"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d >> 13}}
132
+ dt_compare("#<<"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d << 17}}
133
+ dt_compare("#<=> DateTime"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); d2 = dc.civil(2010, 1, 2, 3, 4, 5); n.times{d <=> d2}}
134
+ dt_compare("#<=> Date"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); d2 = Date.civil(2010, 1, 2); n.times{d <=> d2}}
135
+ dt_compare("#<=> Integer"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); d2 = dc.civil(2010, 1, 2).jd; n.times{d <=> d2}}
136
+ dt_compare("#=== Date"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); d2 = Date.civil(2010, 1, 2); n.times{d === d2}}
137
+ dt_compare("#=== DateTime"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); d2 = dc.civil(2010, 1, 2, 13, 14, 15); n.times{d === d2}}
138
+ dt_compare("#=== Integer"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); d2 = 2010; n.times{d === d2}}
139
+ dt_compare("#ajd"){|dc| d = dc.jd(2010, 13, 43, 57); n.times{d.ajd}}
140
+ dt_compare("#amjd"){|dc| d = dc.jd(2010, 13, 43, 57); n.times{d.amjd}}
141
+ dt_compare("#asctime"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.asctime}}
142
+ dt_compare("#cwday"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.cwday}}
143
+ dt_compare("#cweek"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.cweek}}
144
+ dt_compare("#cwyear"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.cwyear}}
145
+ dt_compare("#day"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.day}}
146
+ dt_compare("#day_fraction"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.day_fraction}}
147
+ dt_compare("#downto"){|dc| d = dc.civil(2010, 1, 10, 13, 43, 57); d2 = dc.civil(2010, 1, 1, 13, 43, 56); n.times{d.downto(d2){}}}
148
+ dt_compare("#eql?"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); d2 = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.eql? d2}}
149
+ dt_compare("#gregorian"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.gregorian}}
150
+ dt_compare("#gregorian?"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.gregorian?}}
151
+ dt_compare("#hash"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.hash}}
152
+ dt_compare("#hour"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.hour}}
153
+ dt_compare("#inspect"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.inspect}}
154
+ dt_compare("#jd"){|dc| d = dc.jd(2010, 13, 43, 57); n.times{d.jd}}
155
+ dt_compare("#julian?"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.julian?}}
156
+ dt_compare("#ld"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.ld}}
157
+ dt_compare("#leap?"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.leap?}}
158
+ dt_compare("#min"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.min}}
159
+ dt_compare("#mjd"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.mjd}}
160
+ dt_compare("#month"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.month}}
161
+ dt_compare("#new_offset"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.new_offset 0}}
162
+ dt_compare("#new_start"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.new_start 0}}
163
+ dt_compare("#next"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.next}}
164
+ dt_compare("#offset"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.offset}}
165
+ dt_compare("#sec"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.sec}}
166
+ dt_compare("#sec_fraction"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.sec_fraction}}
167
+ dt_compare("#start"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.start}}
168
+ dt_compare("#step"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); d2 = dc.civil(2010, 1, 10, 13, 43, 58); n.times{d.step(d2){}}}
169
+ dt_compare("#strftime"){|dc| d = dc.civil(2010, 1, 10, 13, 43, 57); n.times{d.strftime('%+')}}
170
+ dt_compare("#to_s"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.to_s}}
171
+ dt_compare("#upto"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); d2 = dc.civil(2010, 1, 10); n.times{d.upto(d2){}}}
172
+ dt_compare("#wday"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.wday}}
173
+ dt_compare("#yday"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.yday}}
174
+ dt_compare("#year"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.year}}
175
+ dt_compare("#zone"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.zone}}
176
+
177
+ compare(".jd.to_s"){|dc|n.times{dc.jd(2010).to_s}}
178
+ compare(".jd.(year|month|day)"){|dc| n.times{d = dc.jd(2010); d.year; d.month; d.day}}
179
+ compare(".civil.jd"){|dc| n.times{dc.civil(2010, 1, 1).jd}}
180
+
181
+ dt_compare(".now.to_s"){|dc|n.times{dc.now.to_s}}
182
+ dt_compare(".now.(year|month|day|hour|min|sec)"){|dc| n.times{d = dc.now; d.year; d.month; d.day; d.hour; d.min; d.sec}}
183
+ dt_compare(".civil.jd"){|dc| n.times{dc.civil(2010, 1, 1, 13, 43, 57).jd}}
184
+
185
+ compare(" Marshal.dump"){|dc| d = dc.civil(2010, 1, 1); n.times{Marshal.dump(d)}}
186
+ compare(" Marshal.load"){|dc| d = Marshal.dump(dc.civil(2010, 1, 1)); n.times{Marshal.load(d)}}
187
+
188
+ dt_compare(" Marshal.dump"){|dc| d = dc.now; n.times{Marshal.dump(d)}}
189
+ dt_compare(" Marshal.load"){|dc| d = Marshal.dump(dc.now); n.times{Marshal.load(d)}}
190
+
191
+ if RUBY_VERSION >= '1.9.0.'
192
+ compare("._httpdate"){|dc| n.times{dc._httpdate("Thu, 12 Aug 2010 00:00:00 GMT")}}
193
+ compare("._iso8601"){|dc| n.times{dc._iso8601("2010-08-12")}}
194
+ compare("._jisx0301"){|dc| n.times{dc._jisx0301("H22.08.12")}}
195
+ compare("._rfc2822"){|dc| n.times{dc._rfc2822("Thu, 12 Aug 2010 00:00:00 +0000")}}
196
+ compare("._rfc3339"){|dc| n.times{dc._rfc3339("2010-08-12T08:27:18-07:00")}}
197
+ compare("._xmlschema"){|dc| n.times{dc._xmlschema("2010-08-12")}}
198
+ compare(".httpdate"){|dc| n.times{dc.httpdate("Thu, 12 Aug 2010 00:00:00 GMT")}}
199
+ compare(".iso8601"){|dc| n.times{dc.iso8601("2010-08-12")}}
200
+ compare(".jisx0301"){|dc| n.times{dc.jisx0301("H22.08.12")}}
201
+ compare(".rfc2822"){|dc| n.times{dc.rfc2822("Thu, 12 Aug 2010 00:00:00 +0000")}}
202
+ compare(".rfc3339"){|dc| n.times{dc.rfc3339("2010-08-12T08:27:18-07:00")}}
203
+ compare(".xmlschema"){|dc| n.times{dc.xmlschema("2010-08-12")}}
204
+
205
+ dt_compare("._httpdate"){|dc| n.times{dc._httpdate("Thu, 12 Aug 2010 15:27:12 GMT")}}
206
+ dt_compare("._iso8601"){|dc| n.times{dc._iso8601("2010-08-12T08:27:18-07:00")}}
207
+ dt_compare("._jisx0301"){|dc| n.times{dc._jisx0301("H22.08.12T08:27:23-07:00")}}
208
+ dt_compare("._rfc2822"){|dc| n.times{dc._rfc2822("Thu, 12 Aug 2010 08:27:31 -0700")}}
209
+ dt_compare("._rfc3339"){|dc| n.times{dc._rfc3339("2010-08-12T08:27:18-07:00")}}
210
+ dt_compare("._xmlschema"){|dc| n.times{dc._xmlschema("2010-08-12T08:27:18-07:00")}}
211
+ dt_compare(".httpdate"){|dc| n.times{dc.httpdate("Thu, 12 Aug 2010 15:27:12 GMT")}}
212
+ dt_compare(".iso8601"){|dc| n.times{dc.iso8601("2010-08-12T08:27:18-07:00")}}
213
+ dt_compare(".jisx0301"){|dc| n.times{dc.jisx0301("H22.08.12T08:27:23-07:00")}}
214
+ dt_compare(".rfc2822"){|dc| n.times{dc.rfc2822("Thu, 12 Aug 2010 08:27:31 -0700")}}
215
+ dt_compare(".rfc3339"){|dc| n.times{dc.rfc3339("2010-08-12T08:27:18-07:00")}}
216
+ dt_compare(".xmlschema"){|dc| n.times{dc.xmlschema("2010-08-12T08:27:18-07:00")}}
217
+
218
+ compare("#httpdate"){|dc| d = dc.civil(2010, 1, 1); n.times{d.httpdate}}
219
+ compare("#iso8601"){|dc| d = dc.civil(2010, 1, 1); n.times{d.iso8601}}
220
+ compare("#jisx0301"){|dc| d = dc.civil(2010, 1, 1); n.times{d.jisx0301}}
221
+ compare("#next_day"){|dc| d = dc.civil(2010, 1, 1); n.times{d.next_day}}
222
+ compare("#next_month"){|dc| d = dc.civil(2010, 1, 1); n.times{d.next_month}}
223
+ compare("#next_year"){|dc| d = dc.civil(2010, 1, 1); n.times{d.next_year}}
224
+ compare("#prev_day"){|dc| d = dc.civil(2010, 1, 1); n.times{d.prev_day}}
225
+ compare("#prev_month"){|dc| d = dc.civil(2010, 1, 1); n.times{d.prev_month}}
226
+ compare("#prev_year"){|dc| d = dc.civil(2010, 1, 1); n.times{d.prev_year}}
227
+ compare("#rfc2822"){|dc| d = dc.civil(2010, 1, 1); n.times{d.rfc2822}}
228
+ compare("#rfc3339"){|dc| d = dc.civil(2010, 1, 1); n.times{d.rfc3339}}
229
+ compare("#sunday?"){|dc| d = dc.civil(2010, 1, 1); n.times{d.sunday?}}
230
+ compare("#to_date"){|dc| d = dc.civil(2010, 1, 1); n.times{d.to_date}}
231
+ compare("#to_datetime"){|dc| d = dc.civil(2010, 1, 1); n.times{d.to_datetime}}
232
+ compare("#to_time"){|dc| d = dc.civil(2010, 1, 1); n.times{d.to_time}}
233
+ compare("#xmlschema"){|dc| d = dc.civil(2010, 1, 1); n.times{d.xmlschema}}
234
+
235
+ dt_compare("#httpdate"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.httpdate}}
236
+ dt_compare("#iso8601"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.iso8601}}
237
+ dt_compare("#jisx0301"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.jisx0301}}
238
+ dt_compare("#next_day"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.next_day}}
239
+ dt_compare("#next_month"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.next_month}}
240
+ dt_compare("#next_year"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.next_year}}
241
+ dt_compare("#prev_day"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.prev_day}}
242
+ dt_compare("#prev_month"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.prev_month}}
243
+ dt_compare("#prev_year"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.prev_year}}
244
+ dt_compare("#rfc2822"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.rfc2822}}
245
+ dt_compare("#rfc3339"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.rfc3339}}
246
+ dt_compare("#sunday?"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.sunday?}}
247
+ dt_compare("#to_date"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.to_date}}
248
+ dt_compare("#to_datetime"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.to_datetime}}
249
+ dt_compare("#to_time"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.to_time}}
250
+ dt_compare("#xmlschema"){|dc| d = dc.civil(2010, 1, 1, 13, 43, 57); n.times{d.xmlschema}}
251
+
252
+ compare(" Time#to_time"){|dc| t = Time.now; n.times{t.to_time}}
253
+ compare(" Time#to_date"){|dc| t = Time.now; n.times{t.to_date}}
254
+ dt_compare(" Time#to_datetime"){|dc| t = Time.now; n.times{t.to_datetime}}
255
+ else
256
+ compare(".ajd_to_amjd"){|dc| n.times{dc.ajd_to_amjd(1)}}
257
+ compare(".ajd_to_jd"){|dc| n.times{dc.ajd_to_jd(1)}}
258
+ compare(".amjd_to_ajd"){|dc| n.times{dc.amjd_to_ajd(1)}}
259
+ compare(".civil_to_jd"){|dc| n.times{dc.civil_to_jd(1, 1, 1)}}
260
+ compare(".commercial_to_jd"){|dc| n.times{dc.commercial_to_jd(2010, 1, 1)}}
261
+ compare(".day_fraction_to_time"){|dc| n.times{dc.day_fraction_to_time(0.5)}}
262
+ compare(".gregorian? Date"){|dc| d = Date.jd(1); n.times{dc.gregorian?(d, 1)}}
263
+ compare(".gregorian? Integer"){|dc| n.times{dc.gregorian?(1, 1)}}
264
+ compare(".jd_to_ajd"){|dc| n.times{dc.jd_to_ajd(2000, 0)}}
265
+ compare(".jd_to_civil"){|dc| n.times{dc.jd_to_civil(2010)}}
266
+ compare(".jd_to_commercial"){|dc| n.times{dc.jd_to_commercial(2010)}}
267
+ compare(".jd_to_ld"){|dc| n.times{dc.jd_to_ld(2010)}}
268
+ compare(".jd_to_mjd"){|dc| n.times{dc.jd_to_mjd(2010)}}
269
+ compare(".jd_to_ordinal"){|dc| n.times{dc.jd_to_ordinal(2010)}}
270
+ compare(".jd_to_wday"){|dc| n.times{dc.jd_to_wday(2010)}}
271
+ compare(".julian? Date"){|dc| d = Date.jd(1); n.times{dc.julian?(d, 1)}}
272
+ compare(".julian? Integer"){|dc| n.times{dc.julian?(1, 1)}}
273
+ compare(".ld_to_jd"){|dc| n.times{dc.ld_to_jd(2010)}}
274
+ compare(".mjd_to_jd"){|dc| n.times{dc.mjd_to_jd(2010)}}
275
+ compare(".ordinal_to_jd"){|dc| n.times{dc.ordinal_to_jd(2012, 100)}}
276
+ compare(".time_to_day_fraction"){|dc| n.times{dc.time_to_day_fraction(7, 13, 17)}}
277
+ compare(".valid_time?"){|dc| n.times{dc.valid_time?(13, 35, 52)}}
278
+ compare(".zone_to_diff"){|dc| s = "+0800"; n.times{dc.zone_to_diff(s)}}
279
+ end
@@ -0,0 +1,11 @@
1
+ require 'date'
2
+
3
+ def mem_usage
4
+ `ps -o vsz -p #{$$}`.split.last.to_i
5
+ end
6
+ n = 50000
7
+ GC.start
8
+ GC.disable
9
+ start_mem = mem_usage
10
+ n.times{DateTime.civil(2010, 11, 21, 13, 43, 57)}
11
+ puts(mem_usage - start_mem)
@@ -0,0 +1,14 @@
1
+ require 'date'
2
+
3
+ def mem_usage
4
+ `ps -o vsz -p #{$$}`.split.last.to_i
5
+ end
6
+ n = 100000
7
+ GC.start
8
+ start_mem = mem_usage
9
+ m = (0...n).map{nil}
10
+ GC.start
11
+ array_usage = mem_usage - start_mem
12
+ m = (0...n).map{DateTime.civil}
13
+ GC.start
14
+ puts(mem_usage - start_mem - array_usage)
@@ -0,0 +1,11 @@
1
+ require 'date'
2
+
3
+ def mem_usage
4
+ `ps -o vsz -p #{$$}`.split.last.to_i
5
+ end
6
+ n = 100000
7
+ GC.start
8
+ GC.disable
9
+ start_mem = mem_usage
10
+ n.times{Date.civil(2010, 11, 21)}
11
+ puts(mem_usage - start_mem)
@@ -0,0 +1,14 @@
1
+ require 'date'
2
+
3
+ def mem_usage
4
+ `ps -o vsz -p #{$$}`.split.last.to_i
5
+ end
6
+ n = 100000
7
+ GC.start
8
+ start_mem = mem_usage
9
+ m = (0...n).map{nil}
10
+ GC.start
11
+ array_usage = mem_usage - start_mem
12
+ m = (0...n).map{Date.jd}
13
+ GC.start
14
+ puts(mem_usage - start_mem - array_usage)
@@ -0,0 +1,91 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+
5
+ command = :run
6
+ lib = File.expand_path('../../ext', __FILE__)
7
+
8
+ opts = OptionParser.new do |opts|
9
+ opts.banner = "home_run: Fast Date/DateTime classes for ruby"
10
+ opts.define_head "Usage: home_run (--install | --uninstall | --bench | --spec | command)"
11
+ opts.separator ""
12
+ opts.separator "Options:"
13
+
14
+ opts.on_tail("--install", "install to site_ruby") do
15
+ command = :install
16
+ end
17
+
18
+ opts.on_tail("--uninstall", "uninstall from site_ruby") do
19
+ command = :uninstall
20
+ end
21
+
22
+ opts.on_tail("--bench", "run comparative benchmarks") do
23
+ command = :bench
24
+ end
25
+
26
+ opts.on_tail("--spec", "run the specs (requires mspec)") do
27
+ command = :spec
28
+ end
29
+ end
30
+ if ARGV.empty?
31
+ $stderr.puts opts.help
32
+ exit(1)
33
+ end
34
+ opts.order!
35
+
36
+ case command
37
+ when :bench
38
+ Dir.chdir(File.join(lib, '..'))
39
+ require 'rbconfig'
40
+ ENV['RUBY'] = File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])
41
+ require 'rubygems'
42
+ require 'rake'
43
+ load './Rakefile'
44
+ Rake::Task[:bench_all].invoke
45
+ when :spec
46
+ Dir.chdir(File.join(lib, '..'))
47
+ require 'rbconfig'
48
+ ENV['PATH'] = [RbConfig::CONFIG['bindir'], ENV['PATH']].join(File::PATH_SEPARATOR)
49
+ ENV['RUBY'] = File.join(RbConfig::CONFIG['ruby_install_name'])
50
+ require 'rubygems'
51
+ require 'rake'
52
+ load './Rakefile'
53
+ Rake::Task[:default].invoke
54
+ when :install
55
+ Dir.chdir(lib)
56
+ require 'rbconfig'
57
+ require 'fileutils'
58
+ FUV = FileUtils::Verbose
59
+ FUV.cp("date.rb", RbConfig::CONFIG['sitelibdir'])
60
+ FUV.mkdir_p(File.join(RbConfig::CONFIG['sitelibdir'], 'date'))
61
+ FUV.cp("date/format.rb", File.join(RbConfig::CONFIG['sitelibdir'], 'date'))
62
+ if File.exists?("date_ext.#{RbConfig::CONFIG['DLEXT']}")
63
+ FUV.cp("date_ext.#{RbConfig::CONFIG['DLEXT']}", RbConfig::CONFIG['sitearchdir'])
64
+ else
65
+ # Windows binary gem files
66
+ if File.exists?('1.8/date_ext.so')
67
+ FUV.mkdir_p(File.join(RbConfig::CONFIG['sitearchdir'], '1.8'))
68
+ FUV.cp("1.8/date_ext.so", File.join(RbConfig::CONFIG['sitearchdir'], '1.8'))
69
+ end
70
+ if File.exists?('1.9/date_ext.so')
71
+ FUV.mkdir_p(File.join(RbConfig::CONFIG['sitearchdir'], '1.9'))
72
+ FUV.cp("1.9/date_ext.so", File.join(RbConfig::CONFIG['sitearchdir'], '1.9'))
73
+ end
74
+ end
75
+ when :uninstall
76
+ require 'rbconfig'
77
+ require 'fileutils'
78
+ FUV = FileUtils::Verbose
79
+ FUV.rm_f(File.join(RbConfig::CONFIG['sitelibdir'], 'date.rb'))
80
+ FUV.rm_f(File.join(RbConfig::CONFIG['sitelibdir'], 'date/format.rb'))
81
+ FUV.rmdir(File.join(RbConfig::CONFIG['sitelibdir'], 'date')) rescue nil
82
+ FUV.rm_f(File.join(RbConfig::CONFIG['sitearchdir'], "date_ext.#{RbConfig::CONFIG['DLEXT']}"))
83
+ FUV.rm_f(File.join(RbConfig::CONFIG['sitearchdir'], '1.8/date_ext.so'))
84
+ FUV.rmdir(File.join(RbConfig::CONFIG['sitearchdir'], '1.8')) rescue nil
85
+ FUV.rm_f(File.join(RbConfig::CONFIG['sitearchdir'], '1.9/date_ext.so'))
86
+ FUV.rmdir(File.join(RbConfig::CONFIG['sitearchdir'], '1.9')) rescue nil
87
+ else
88
+ ENV['RUBYOPT'] = "-rdate #{ENV['RUBYOPT']}"
89
+ ENV['RUBYLIB'] = [lib, ENV['RUBYLIB']].join(File::PATH_SEPARATOR)
90
+ exec(*ARGV)
91
+ end
@@ -0,0 +1,12 @@
1
+ unless ENV['HOME']
2
+ if ENV['USERPROFILE']
3
+ ENV['HOME'] = ENV['USERPROFILE']
4
+ elsif ENV['HOMEDRIVE'] && ENV['HOMEPATH']
5
+ ENV['HOME'] = ENV['HOMEDRIVE'] + ENV['HOMEPATH']
6
+ end
7
+ end
8
+
9
+ class MSpecScript
10
+ set :flags, %w'-I ext -r date'
11
+ set :files, ['spec/date/*', 'spec/datetime/*']
12
+ end
Binary file
Binary file
@@ -0,0 +1,7 @@
1
+ begin
2
+ require "date_ext"
3
+ rescue LoadError
4
+ raise unless RUBY_PLATFORM =~ /win|w32/
5
+ require "#{RUBY_VERSION[0...3]}/date_ext"
6
+ end
7
+ require "date/format" unless defined?(Date::Format)