#!/usr/bin/ruby puts RUBY_VERSION # => 1.8.6
#!/usr/local/bin/ruby1.9 puts RUBY_VERSION # => 1.9.1
#!/usr/bin/ruby puts RUBY_VERSION # => 1.8.6
#!/usr/local/bin/ruby1.9 puts RUBY_VERSION # => 1.9.1
But first things first, here some figures about the test environement:
function index(){
$jobs = $this->Job->find('all');
$this->set('jobs', $jobs);
}
I put only 3 rows in the database table, so that reading from it takes virtually no time and we can better see the time consumed by the framework itself.ab -n 50 -c 1 http://127.0.0.1:3000/jobsLast thing I made, was a very small and straight forward PHP script, that does the same job. This way I had a benchmark of a script using only plain vanilla PHP with no framework overhead.
CakePHP Time per request: 365.572 [ms] (mean) Rails (RAILS_ENV=development) Time per request: 105.029 [ms] (mean) Rails (RAILS_ENV=production) Time per request: 30.318 [ms] (mean) Pure PHP Time per request: 9.026 [ms] (mean)Honestly I was quite surprised. There's so much talk about Ruby being slow, which is surely true when compared to Java. Also PHP is faster in microbenchmarks. But it seems to me that PHP is only really fast when used as much as possible straight forward, this is what PHP was designed for. When it comes to build frameworks and OOP there're better tools.
Rails (RAILS_ENV=development)
=============================
ab -n 50 -c 1 http://127.0.0.1:3000/jobs
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient).....done
Server Software: Mongrel
Server Hostname: 127.0.0.1
Server Port: 3000
Document Path: /jobs
Document Length: 3043 bytes
Concurrency Level: 1
Time taken for tests: 5.251 seconds
Complete requests: 50
Failed requests: 0
Write errors: 0
Total transferred: 178251 bytes
HTML transferred: 152150 bytes
Requests per second: 9.52 [#/sec] (mean)
Time per request: 105.029 [ms] (mean)
Time per request: 105.029 [ms] (mean, across all concurrent requests)
Transfer rate: 33.15 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.8 0 6
Processing: 74 105 64.5 83 318
Waiting: 73 103 63.6 83 317
Total: 74 105 64.7 84 318
Percentage of the requests served within a certain time (ms)
50% 84
66% 86
75% 88
80% 91
90% 237
95% 304
98% 318
99% 318
100% 318 (longest request)
RAILS (RAILS_ENV=production)
============================
ab -n 50 -c 1 http://127.0.0.1:3000/jobs
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient).....done
Server Software: Mongrel
Server Hostname: 127.0.0.1
Server Port: 3000
Document Path: /jobs
Document Length: 3043 bytes
Concurrency Level: 1
Time taken for tests: 1.516 seconds
Complete requests: 50
Failed requests: 0
Write errors: 0
Total transferred: 178236 bytes
HTML transferred: 152150 bytes
Requests per second: 32.98 [#/sec] (mean)
Time per request: 30.318 [ms] (mean)
Time per request: 30.318 [ms] (mean, across all concurrent requests)
Transfer rate: 114.82 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.3 0 3
Processing: 17 30 32.8 21 187
Waiting: 16 29 32.8 20 186
Total: 17 30 32.8 21 187
Percentage of the requests served within a certain time (ms)
50% 21
66% 24
75% 25
80% 26
90% 34
95% 138
98% 187
99% 187
100% 187 (longest request)
CAKEPHP
=======
ab -n 50 -c 1 http://jobscake/jobs
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking jobscake (be patient).....done
Server Software: Apache/2.2.9
Server Hostname: jobscake
Server Port: 80
Document Path: /jobs
Document Length: 4176 bytes
Concurrency Level: 1
Time taken for tests: 18.279 seconds
Complete requests: 50
Failed requests: 49
(Connect: 0, Receive: 0, Length: 49, Exceptions: 0)
Write errors: 0
Total transferred: 217781 bytes
HTML transferred: 200781 bytes
Requests per second: 2.74 [#/sec] (mean)
Time per request: 365.572 [ms] (mean)
Time per request: 365.572 [ms] (mean, across all concurrent requests)
Transfer rate: 11.64 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.4 0 3
Processing: 329 365 42.2 355 570
Waiting: 329 364 39.6 355 543
Total: 329 365 42.4 356 572
Percentage of the requests served within a certain time (ms)
50% 356
66% 364
75% 372
80% 374
90% 390
95% 409
98% 572
99% 572
100% 572 (longest request)
PURE PHP
========
ab -n 50 -c 1 http://localhost/develop/projects/Test/pure_php_jobs/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient).....done
Server Software: Apache/2.2.9
Server Hostname: localhost
Server Port: 80
Document Path: /develop/projects/Test/pure_php_jobs/
Document Length: 1923 bytes
Concurrency Level: 1
Time taken for tests: 0.451 seconds
Complete requests: 50
Failed requests: 0
Write errors: 0
Total transferred: 107200 bytes
HTML transferred: 96150 bytes
Requests per second: 110.80 [#/sec] (mean)
Time per request: 9.026 [ms] (mean)
Time per request: 9.026 [ms] (mean, across all concurrent requests)
Transfer rate: 231.98 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.2 0 1
Processing: 5 9 7.3 6 53
Waiting: 3 7 7.7 5 53
Total: 5 9 7.3 6 53
Percentage of the requests served within a certain time (ms)
50% 6
66% 8
75% 10
80% 12
90% 13
95% 16
98% 53
99% 53
100% 53 (longest request)
condition ifTrue: [ doSomething ] ifFalse: [ doSomethingElse ]If the condition is true the first block will be executed, if false the second block will executed.
class TrueClass
def if_true
yield
self
end
def if_false
self
end
alias if if_true
alias else if_false
end
class FalseClass
def if_true
self
end
def if_false
yield
self
end
alias if if_true
alias else if_false
end
As you can see I always return self, so that we chain the methods.
Now we can write:
i = 5
(i > 3).if_true {puts 'true'}.if_false {puts 'false'}
Using the alias methods we can write it in the more common form:
i = 5
(i > 3).if {puts 'true'}.else {puts 'false'}
or
i = 5 (i > 3).if do puts 'true' end.else do puts 'false' end
NameError: uninitialized constant Nokogiri::CSS::XMLAfter a I while figured out, that you first have to require nokogiri explicitly. So my steps for webrat are now beginning with:
require 'nokogiri'
require "webrat/rails"
steps_for :webrat do
When "visits '$link'" do |link|
visits link
end
...
To check your gem versions against mine, here an extract of my gem list:
Rails (2.2.2) webrat (0.3.2) nokogiri (1.1.0) libxml-ruby (0.9.7) libxslt-ruby (0.9.1)
./configure --prefix=/usr/local --program-suffix=1.9 make sudo make install
./configure --prefix=/usr/local make sudo make installNow compiling ruby should work as expected, don't forget to point to your new compilied readline library. In your ruby directory:
./configure --prefix=/usr/local --program-suffix=1.9 --with-readline-dir=/usr/local make sudo make installNow you have both ruby versions in parallel, try ruby -v and ruby1.9 -v