comparison Looping.st @ 5:861b93741d60

id:sumim氏のSmalltalk版とRuby版のコードを追加。
author "uncorrelated zombie" <uncorrelated@yahoo.co.jp>
date Thu, 17 Feb 2011 11:32:17 +0900
parents
children
comparison
equal deleted inserted replaced
3:57283e4fdd4b 5:861b93741d60
1 'From Squeak4.2 of 4 February 2011 [latest update: #10966] on 17 February 2011 at 8:44:09 am'!
2 Object subclass: #Looping
3 instanceVariableNames: 'n0'
4 classVariableNames: ''
5 poolDictionaries: ''
6 category: 'Benchmark-Looping'!
7
8 !Looping methodsFor: 'calculation' stamp: 'sumim 2/17/2011 00:17'!
9 calc: n
10 | n1 |
11 n1 := n0 + (1 - (2 * (n \\ 2))).
12 n0 := n.
13 ^n1! !
14
15 !Looping methodsFor: 'initializing' stamp: 'sumim 2/16/2011 23:59'!
16 initialize
17 n0 := 0! !
18
19
20 !Looping class methodsFor: 'benchmark' stamp: 'sumim 2/17/2011 00:52'!
21 benchmark
22 "self benchmark"
23 | l n t1 t2 |
24 l := Looping new.
25 n := 1.
26 t1 := Time millisecondClockValue.
27 2147483647 timesRepeat: [
28 n := l calc: n
29 ].
30 t2 := Time millisecondClockValue.
31 Transcript cr; show: n printString.
32 Transcript cr; show: 'Smalltalk'; tab; show: (t2 - t1 / 1000.0) printString! !
33
34 Looping benchmark!
35