# CGIAlt 0.0.1 released - an alternative library of 'cgi.rb'

**URL:** <https://www.ruby-forum.com/t/cgialt-0-0-1-released-an-alternative-library-of-cgi-rb/122568>\
**Category:** Ruby\
**Created:** [December 9, 2007, 5:31pm UTC](https://www.ruby-forum.com/t/cgialt-0-0-1-released-an-alternative-library-of-cgi-rb/122568 "2007-12-09T17:31:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![makoto\_kuwata](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a4c791/32.png) [@makoto\_kuwata](https://www.ruby-forum.com/u/makoto_kuwata)\
**Post date:** [December 9, 2007, 5:31pm UTC](https://www.ruby-forum.com/t/cgialt-0-0-1-released-an-alternative-library-of-cgi-rb/122568/1 "2007-12-09T17:31:16Z")

</div>

I have released CGIAlt 0.0.1.  
[http://rubyforge.org/projects/cgiext/](http://rubyforge.org/projects/cgiext/)

CGIAlt is an alternative library of ‘cgi.rb’.

- Compatible with ‘cgi.rb’ and CGI class
- Faster than ‘cgi.rb’
- Available with CGIExt (which is an implementation of cgi.rb in C  
extension)

The following is an example of benchmark.

```
                                 cgi.rb CGIAlt CGIAlt

```

+CGIExt

* * *

require “cgi” (x1000) 13.16 7.89 ( 67%) 9.18  
( 43%)  
CGI#new (simple) (x100000) 20.34 14.53 ( 40%) 12.46  
( 63%)  
CGI#new (comple) (x100000) 26.62 20.10 ( 32%) 13.19  
(102%)  
CGI#header (simple) (x1000000) 12.68 6.05 (110%) 6.04  
(110%)  
CGI#header (complex) (x1000000) 43.52 36.26 ( 20%) 36.62  
( 19%)

See [http://cgiext.rubyforge.org/](http://cgiext.rubyforge.org/) for details.

---

<div class="post-metadata">

**Author:** ![makoto\_kuwata](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a4c791/32.png) [@makoto\_kuwata](https://www.ruby-forum.com/u/makoto_kuwata)\
**Post date:** [December 9, 2007, 8:17pm UTC](https://www.ruby-forum.com/t/cgialt-0-0-1-released-an-alternative-library-of-cgi-rb/122568/2 "2007-12-09T20:17:28Z")

</div>

On Dec 9, 2007, at 9:29 AM, makoto kuwata wrote:

> The following is an example of benchmark.  
> CGI#new (comple) (x100000) 26.62 20.10 ( 32%) 13.19  
> makoto kuwata

any thoughts on why i’m not seeing any speedup with this:

#! /opt/local/bin/ruby  
require ‘rubygems’  
require ‘cgi’  
require ‘fcgi’  
require ‘cgiext’

start\_time = Time::now

memory\_session = Hash::new{|h,k| h[k] = {}}

FCGI::each\_cgi do |cgi|  
this\_time = Time::now

# hack to get around ruby session bug

session = memory\_session[[cgi.cookies  
[‘\_session\_id’]].compact.flatten.first]  
last\_time = session[‘last\_time’]  
session[‘last\_time’] = this\_time

content = \<\<-html

* * *
  
 **START\_TIME** @ _#{ start\_time }_  

* * *
  
 **THIS\_TIME** @ _#{ this\_time }_  

* * *
  
 **LAST\_TIME** @ _#{ last\_time }_  

* * *
  
html

cgi.out { content }  
end

??

cheers.

a @ [http://codeforpeople.com/](http://codeforpeople.com/)

---

<div class="post-metadata">

**Author:** ![makoto\_kuwata](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a4c791/32.png) [@makoto\_kuwata](https://www.ruby-forum.com/u/makoto_kuwata)\
**Post date:** [December 12, 2007, 8:49pm UTC](https://www.ruby-forum.com/t/cgialt-0-0-1-released-an-alternative-library-of-cgi-rb/122568/3 "2007-12-12T20:49:24Z")

</div>

Hi ara, thank you for trying CGIAlt and CGIExt.

I have released new version of CGIAlt (0.0.2).  
It now supports FastCGI.  
Could you try new one?

–  
makoto kuwata

---

<div class="post-metadata">

**Author:** ![makoto\_kuwata](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a4c791/32.png) [@makoto\_kuwata](https://www.ruby-forum.com/u/makoto_kuwata)\
**Post date:** [December 12, 2007, 9:16pm UTC](https://www.ruby-forum.com/t/cgialt-0-0-1-released-an-alternative-library-of-cgi-rb/122568/4 "2007-12-12T21:16:48Z")

</div>

On Dec 11, 2007, at 7:10 AM, makoto kuwata wrote:

> Hi ara, thank you for trying CGIAlt and CGIExt.
> 
> I have released new version of CGIAlt (0.0.2).  
> It now supports FastCGI.  
> Could you try new one?

sure.

can you confirm that, for cgi i should do

require ‘cgialt’  
require ‘cgiext’

and, for fcgi

require ‘cgialt’  
require ‘cgialt/fcgi’  
require ‘cgiext’

and that, in both cases, i do not need to require either cgi.rb or  
fcgi.{so,rb} ??

cheers.

a @ [http://codeforpeople.com/](http://codeforpeople.com/)

---

<div class="post-metadata">

**Author:** ![makoto\_kuwata](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a4c791/32.png) [@makoto\_kuwata](https://www.ruby-forum.com/u/makoto_kuwata)\
**Post date:** [December 13, 2007, 9:54am UTC](https://www.ruby-forum.com/t/cgialt-0-0-1-released-an-alternative-library-of-cgi-rb/122568/5 "2007-12-13T09:54:06Z")

</div>

“ara.t.howard” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> and i don’t really see a huge improvement - but it’s a very simply  
> program that may not take advantage of the performance features. can  
> you suggest a fcgi that should see a significant speedup?

CGIAlt and CGIExt are not the silver bullet for performance.  
If CGI class and it’s methods were bottle neck of your application,  
CGIAlt and CGIExt would be good solution.  
But if not, you can’t find improvement of performance.

The following is an example of benchmarks. These benchmark scripts are  
included in CGIAlt package and you can try them.

## Table 1. summary of benchmark cgi.rb CGIAlt CGIAlt +CGIExt

require “cgi” (x1000) 13.16 7.89 ( 67%) 9.18  
( 43%)  
CGI#new (simple) (x100000) 20.34 14.53 ( 40%) 12.46  
( 63%)  
CGI#new (comple) (x100000) 26.62 20.10 ( 32%) 13.19  
(102%)  
CGI#header (simple) (x1000000) 12.68 6.05 (110%) 6.04  
(110%)  
CGI#header (complex) (x1000000) 43.52 36.26 ( 20%) 36.62  
( 19%)

## Table 2. result of bench.fcgi Time taken for tests Request per second

cgi + fcgi 16.686 [sec] 1198.61 [#/  
sec]  
cgialt + cgialt/fcgi 15.562 [sec] 1285.18 [#/  
sec]  
cgialt + cgialt/fcgi + cgiext 15.310 [sec] 1306.34 [#/  
sec]

CGIExt replaces CGI.escapeHTML and ERB::Util.h and makes them much  
faster.  
If you use a lot of ‘\<%=h var %\>’, CGIExt will improve your  
application’s performance.

---

<div class="post-metadata">

**Author:** ![makoto\_kuwata](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a4c791/32.png) [@makoto\_kuwata](https://www.ruby-forum.com/u/makoto_kuwata)\
**Post date:** [December 12, 2007, 8:57pm UTC](https://www.ruby-forum.com/t/cgialt-0-0-1-released-an-alternative-library-of-cgi-rb/122568/6 "2007-12-12T20:57:43Z")

</div>

On Dec 11, 2007, at 7:10 AM, makoto kuwata wrote:

> Hi ara, thank you for trying CGIAlt and CGIExt.
> 
> I have released new version of CGIAlt (0.0.2).  
> It now supports FastCGI.  
> Could you try new one?

this is what i’m testing:

#! /opt/local/bin/ruby  
require ‘rubygems’  
require ‘cgialt’  
require ‘cgialt/fcgi’  
require ‘cgiext’

start\_time = Time::now

memory\_session = Hash::new{|h,k| h[k] = {}}

FCGI::each\_cgi do |cgi|  
this\_time = Time::now

# hack to get around ruby session bug

session = memory\_session[[cgi.cookies  
[‘\_session\_id’]].compact.flatten.first]  
last\_time = session[‘last\_time’]  
session[‘last\_time’] = this\_time

content = \<\<-html

* * *
  
 **START\_TIME** @ _#{ start\_time }_  

* * *
  
 **THIS\_TIME** @ _#{ this\_time }_  

* * *
  
 **LAST\_TIME** @ _#{ last\_time }_  

* * *
  
html

cgi.out { content }  
end

and i don’t really see a huge improvement - but it’s a very simply  
program that may not take advantage of the performance features. can  
you suggest a fcgi that should see a significant speedup?

a @ [http://codeforpeople.com/](http://codeforpeople.com/)
