rubystone 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f941e6d59acca0cfce7930f51e4d22099bcde511
4
+ data.tar.gz: a84850eba9b8b1d30b0043c3d5fcf9844bb53cf9
5
+ SHA512:
6
+ metadata.gz: c0f79750646566184da1f9ec476396f7032db03ff1c148449cfc547f868fce3adb1b15a777620f6c4c5dfa1dcddd1425da399c43438e3efec42d416169c6e0a1
7
+ data.tar.gz: e7f2f93b37e5e2751b81f5c7f84c4ed61b33fb7a6909839489ce56f3e3b7a60e2ade59f48836478008f0be9857d133c679eb5ad64eb2337ac58a5c17c2135dac
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2014 Maurizio De Santis
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # ["RUBYSTONE" Benchmark Program](https://github.com/mdesantis/rubystone)
2
+
3
+ ## Description
4
+
5
+ This is the Ruby porting of the Python [PYSTONE](http://hg.python.org/cpython/file/fc4ef17c7db8/Lib/test/pystone.py) script. It provides a rough benchmark of the Ruby interpreter via the `rubystone` executable.
6
+
7
+ # Usage
8
+
9
+ Install the gem:
10
+
11
+
12
+ ```
13
+ gem install rubystone
14
+ ```
15
+
16
+ Or clone the project:
17
+
18
+
19
+ ```
20
+ git clone https://github.com/mdesantis/rubystone
21
+ ```
22
+
23
+ Then use the `rubystone` executable:
24
+
25
+
26
+ ```
27
+ $ rubystone
28
+ Rubystone 1.0 cold time for 50000 passes = 0.6164484
29
+ This machine benchmarks at 81109 cold rubystones/second
30
+ Rubystone 1.0 warm time for 50000 passes = 0.6284089
31
+ This machine benchmarks at 79566 warm rubystones/second
32
+
33
+ ```
34
+
35
+ ## Version
36
+
37
+ Ruby/1.0 (corresponds to Python/1.1 PYSTONE version)
38
+
39
+ ## Author
40
+
41
+ Reinhold P. Weicker, CACM Vol 27, No 10, 10/84 pg. 1013.
42
+
43
+ Translated from ADA to C by Rick Richardson.
44
+ Every method to preserve ADA-likeness has been used,
45
+ at the expense of C-ness.
46
+
47
+ Translated from C to Python by Guido van Rossum.
48
+
49
+ Translated from Python to Ruby by [Maurizio De Santis](https://github.com/mdesantis).
50
+
51
+ ## Changes
52
+
53
+ The Ruby version runs two indentical benchmarks sequentially,
54
+ the *cold* run and the *warm* run: the latter is intended for
55
+ platforms with JIT compilation (JRuby, Rubinius).
56
+
57
+ ## Version History
58
+
59
+ <dt>Version 1.0.1</dt> <dd>Generating new gem</dd>
60
+ <dt>Version 1.0</dt> <dd>Porting of Python/1.1 PYSTONE version</dd>
61
+
62
+ ## References
63
+
64
+ [PYSTONE 1.1](http://hg.python.org/cpython/file/fc4ef17c7db8/Lib/test/pystone.py)
65
+
66
+ ## License
67
+
68
+ [MIT](LICENSE)
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/rubystone ADDED
@@ -0,0 +1,275 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ # "RUBYSTONE" Benchmark Program
4
+ #
5
+ # Version: Ruby/1.0 (corresponds to Python/1.1 PYSTONE version)
6
+ #
7
+ # Author: Reinhold P. Weicker, CACM Vol 27, No 10, 10/84 pg. 1013.
8
+ #
9
+ # Translated from ADA to C by Rick Richardson.
10
+ # Every method to preserve ADA-likeness has been used,
11
+ # at the expense of C-ness.
12
+ #
13
+ # Translated from C to Python by Guido van Rossum.
14
+ #
15
+ # Translated from Python to Ruby by Maurizio De Santis.
16
+ #
17
+ # Changes: The Ruby version runs two indentical benchmarks sequentially,
18
+ # the "cold" run and the "warm" run: the latter is intended for
19
+ # platforms with JIT compilation (JRuby, Rubinius).
20
+ #
21
+ # Version History:
22
+ #
23
+ # Version 1.0 (porting of Python/1.1 PYSTONE version)
24
+ #
25
+ # References: PYSTONE 1.1: http://hg.python.org/cpython/file/fc4ef17c7db8/Lib/test/pystone.py
26
+
27
+ LOOPS = 50000
28
+
29
+ VERSION = "1.0"
30
+
31
+ IDENT1, IDENT2, IDENT3, IDENT4, IDENT5 = (1..5).to_a
32
+
33
+ class Record
34
+ attr_accessor :ptr_comp, :discr, :enum_comp, :int_comp, :string_comp
35
+
36
+ def initialize(ptr_comp = nil, discr = 0, enum_comp = 0, int_comp = 0, string_comp = 0)
37
+ @ptr_comp = ptr_comp
38
+ @discr = discr
39
+ @enum_comp = enum_comp
40
+ @int_comp = int_comp
41
+ @string_comp = string_comp
42
+ end
43
+ end
44
+
45
+ def init_globs
46
+ $int_glob = 0
47
+ $bool_glob = false
48
+ $char1_glob = '\0'
49
+ $char2_glob = '\0'
50
+ $array1_glob = [0]*51
51
+ $array2_glob = ([$array1_glob]*51).map { |x| x }
52
+ $ptr_glb = nil
53
+ $ptr_glb_next = nil
54
+ end
55
+
56
+ def main(status, loops = LOOPS)
57
+ init_globs
58
+ benchtime, stones = rubystones(loops)
59
+ puts "Rubystone %s %s time for %d passes = %.7g" % [VERSION, status, loops, benchtime]
60
+ puts "This machine benchmarks at %d %s rubystones/second" % [stones, status]
61
+ end
62
+
63
+ def rubystones(loops = LOOPS)
64
+ proc0(loops)
65
+ end
66
+
67
+ def proc0(loops = LOOPS)
68
+ starttime = Time.now
69
+ loops.times { |i| nil }
70
+ nulltime = Time.now - starttime
71
+
72
+ $ptr_glb_next = Record.new
73
+ $ptr_glb = Record.new
74
+ $ptr_glb.ptr_comp = $ptr_glb_next
75
+ $ptr_glb.discr = IDENT1
76
+ $ptr_glb.enum_comp = IDENT3
77
+ $ptr_glb.int_comp = 40
78
+ $ptr_glb.string_comp = "DHRYSTONE PROGRAM, SOME STRING"
79
+ string1_loc = "DHRYSTONE PROGRAM, 1'ST STRING"
80
+ $array2_glob[8][7] = 10
81
+
82
+ starttime = Time.now
83
+
84
+ loops.times do |i|
85
+ proc5()
86
+ proc4()
87
+
88
+ int_loc1 = 2
89
+ int_loc2 = 3
90
+ string2_loc = "DHRYSTONE PROGRAM, 2'ND STRING"
91
+ enum_loc = IDENT2
92
+ $bool_glob = !func2(string1_loc, string2_loc)
93
+ while int_loc1 < int_loc2 do
94
+ int_loc3 = 5 * int_loc1 - int_loc2
95
+ int_loc3 = proc7(int_loc1, int_loc2)
96
+ int_loc1 = int_loc1 + 1
97
+ end
98
+ proc8($array1_glob, $array2_glob, int_loc1, int_loc3)
99
+ $ptr_glb = proc1($ptr_glb)
100
+ char_index = 'A'
101
+ while char_index <= $char2_glob do
102
+ if enum_loc == func1(char_index, 'C')
103
+ enum_loc = proc6(IDENT1)
104
+ end
105
+ char_index = (char_index.ord+1).chr
106
+ end
107
+ int_loc3 = int_loc2 * int_loc1
108
+ int_loc2 = int_loc3 / int_loc1
109
+ int_loc2 = 7 * (int_loc3 - int_loc2) - int_loc1
110
+ int_loc1 = proc2(int_loc1)
111
+ end
112
+
113
+ benchtime = Time.now - starttime - nulltime
114
+ if benchtime == 0.0
115
+ loopsPerBenchtime = 0.0
116
+ else
117
+ loopsPerBenchtime = loops / benchtime
118
+ end
119
+ return [benchtime, loopsPerBenchtime]
120
+ end
121
+
122
+ def proc1(ptr_par_in)
123
+ ptr_par_in.ptr_comp = next_record = $ptr_glb.dup
124
+ ptr_par_in.int_comp = 5
125
+ next_record.int_comp = ptr_par_in.int_comp
126
+ next_record.ptr_comp = ptr_par_in.ptr_comp
127
+ next_record.ptr_comp = proc3(next_record.ptr_comp)
128
+ if next_record.discr == IDENT1
129
+ next_record.int_comp = 6
130
+ next_record.enum_comp = proc6(ptr_par_in.enum_comp)
131
+ next_record.ptr_comp = $ptr_glb.ptr_comp
132
+ next_record.int_comp = proc7(next_record.int_comp, 10)
133
+ else
134
+ ptr_par_in = next_record.dup
135
+ end
136
+ next_record.ptr_comp = nil
137
+ return ptr_par_in
138
+ end
139
+
140
+ def proc2(int_par_io)
141
+ int_loc = int_par_io + 10
142
+ loop do
143
+ if $char1_glob == 'A'
144
+ int_loc = int_loc - 1
145
+ int_par_io = int_loc - $int_glob
146
+ enum_loc = IDENT1
147
+ end
148
+ if enum_loc == IDENT1
149
+ break
150
+ end
151
+ end
152
+ return int_par_io
153
+ end
154
+
155
+ def proc3(ptr_par_out)
156
+ if $ptr_glb != nil
157
+ ptr_par_out = $ptr_glb.ptr_comp
158
+ else
159
+ $int_glob = 100
160
+ end
161
+ $ptr_glb.int_comp = proc7(10, $int_glob)
162
+ return ptr_par_out
163
+ end
164
+
165
+ def proc4
166
+ bool_loc = $char1_glob == 'A'
167
+ bool_loc = bool_loc || $bool_glob
168
+ $char2_glob = 'B'
169
+ end
170
+
171
+ def proc5
172
+ $char1_glob = 'A'
173
+ $bool_glob = false
174
+ end
175
+
176
+ def proc6(enum_par_in)
177
+ enum_par_out = enum_par_in
178
+ if !func3(enum_par_in)
179
+ enum_par_out = IDENT4
180
+ end
181
+ if enum_par_in == IDENT1
182
+ enum_par_out = IDENT1
183
+ elsif enum_par_in == IDENT2
184
+ if $int_glob > 100
185
+ enum_par_out = IDENT1
186
+ else
187
+ enum_par_out = IDENT4
188
+ end
189
+ elsif enum_par_in == IDENT3
190
+ enum_par_out = IDENT2
191
+ elsif enum_par_in == IDENT4
192
+ nil
193
+ elsif enum_par_in == IDENT5
194
+ enum_par_out = IDENT3
195
+ end
196
+ return enum_par_out
197
+ end
198
+
199
+ def proc7(int_parI1, int_parI2)
200
+ int_loc = int_parI1 + 2
201
+ int_par_out = int_parI2 + int_loc
202
+ return int_par_out
203
+ end
204
+
205
+ def proc8(array1_par, array2_par, int_parI1, int_parI2)
206
+ int_loc = int_parI1 + 5
207
+ array1_par[int_loc] = int_parI2
208
+ array1_par[int_loc+1] = array1_par[int_loc]
209
+ array1_par[int_loc+30] = int_loc
210
+ int_loc.upto(int_loc+1) do |intIndex|
211
+ array2_par[int_loc][intIndex] = int_loc
212
+ end
213
+ array2_par[int_loc][int_loc-1] = array2_par[int_loc][int_loc-1] + 1
214
+ array2_par[int_loc+20][int_loc] = array1_par[int_loc]
215
+ $int_glob = 5
216
+ end
217
+
218
+ def func1(char_par1, char_par2)
219
+ char_loc1 = char_par1
220
+ char_loc2 = char_loc1
221
+ if char_loc2 != char_par2
222
+ return IDENT1
223
+ else
224
+ return IDENT2
225
+ end
226
+ end
227
+
228
+ def func2(str_parI1, str_parI2)
229
+ int_loc = 1
230
+ while int_loc <= 1 do
231
+ if func1(str_parI1[int_loc], str_parI2[int_loc+1]) == IDENT1
232
+ char_loc = 'A'
233
+ int_loc = int_loc + 1
234
+ end
235
+ end
236
+ if char_loc >= 'W' && char_loc <= 'Z'
237
+ int_loc = 7
238
+ end
239
+ if char_loc == 'X'
240
+ return true
241
+ else
242
+ if str_parI1 > str_parI2
243
+ int_loc = int_loc + 7
244
+ return true
245
+ else
246
+ return false
247
+ end
248
+ end
249
+ end
250
+
251
+ def func3(enum_par_in)
252
+ enum_loc = enum_par_in
253
+ return true if enum_loc == IDENT3
254
+ return false
255
+ end
256
+
257
+ def error(msg)
258
+ $stderr.puts msg
259
+ $stderr.puts "usage: rubystone [number_of_loops]"
260
+ exit(100)
261
+ end
262
+
263
+ loops = LOOPS
264
+ nargs = ARGV.size
265
+ if nargs > 1
266
+ error("%d arguments are too many;" % nargs)
267
+ elsif nargs == 1
268
+ if /\A\d+\z/ !~ ARGV[0].to_s
269
+ error("Invalid argument %s; it must be a number" % ARGV[0])
270
+ end
271
+ loops = ARGV[0].to_i
272
+ end
273
+
274
+ main('cold', loops)
275
+ main('warm', loops)
data/rubystone.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = 'rubystone'
3
+ spec.version = '1.0.1'
4
+ spec.license = 'MIT'
5
+ spec.summary = 'Ruby porting of the Python PYSTONE script'
6
+ spec.description = <<-DESC
7
+ It provides a rough benchmark of the Ruby interpreter
8
+ via the `rubystone` executable.
9
+ DESC
10
+ spec.author = 'Maurizio De Santis'
11
+ spec.email = 'desantis.maurizio@gmail.com'
12
+ spec.homepage = 'https://github.com/mdesantis/rubystone'
13
+
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.require_paths = ['.']
17
+
18
+ spec.add_development_dependency 'bundler', '~> 1.6'
19
+ spec.add_development_dependency 'rake', '~> 10.0'
20
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubystone
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Maurizio De Santis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: |
42
+ It provides a rough benchmark of the Ruby interpreter
43
+ via the `rubystone` executable.
44
+ email: desantis.maurizio@gmail.com
45
+ executables:
46
+ - rubystone
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".gitignore"
51
+ - Gemfile
52
+ - LICENSE
53
+ - README.md
54
+ - Rakefile
55
+ - bin/rubystone
56
+ - rubystone.gemspec
57
+ homepage: https://github.com/mdesantis/rubystone
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - "."
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.3.0
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: Ruby porting of the Python PYSTONE script
81
+ test_files: []