diff --git a/static/memory.png b/benchmark/memory.png similarity index 100% rename from static/memory.png rename to benchmark/memory.png diff --git a/static/rps.png b/benchmark/rps.png similarity index 100% rename from static/rps.png rename to benchmark/rps.png diff --git a/static/runtime_with_startup.png b/benchmark/runtime_with_startup.png similarity index 100% rename from static/runtime_with_startup.png rename to benchmark/runtime_with_startup.png diff --git a/guides/performance/readme.md b/guides/performance/readme.md index 0ed36c2..f321656 100644 --- a/guides/performance/readme.md +++ b/guides/performance/readme.md @@ -1,10 +1,8 @@ # Performance -The **Lennarb** is very fast. The following benchmarks were performed on a MacBook Pro (Retina, 13-inch, Early 2013) with 2,7 GHz Intel Core i7 and 8 GB 1867 MHz DDR3. Based on [jeremyevans/r10k](https://github.com/jeremyevans/r10k) using the following [template build](static/r10k/build/lennarb.rb). +The **Lennarb** is very fast. The following benchmarks were performed on a MacBook Pro (Retina, 13-inch, Early 2013) with 2,7 GHz Intel Core i7 and 8 GB 1867 MHz DDR3. Based on [jeremyevans/r10k](https://github.com/jeremyevans/r10k) using the following. All tests are performed using the **Ruby 3.3.0** -All tests are performed using the **Ruby 3.3.0** - -## Benchmark numbers +## Benchmark results This document contains the benchmarks comparing **Lennarb** with other routers based on Rack. Metrics evaluated include Requests per Second, Initial memory usage and Startup time. @@ -41,21 +39,42 @@ This table shows the initial memory usage in KB. Lower values indicate lower mem This table shows the startup time in seconds. Lower values indicate faster startup times. - ## Graphs -### Requests per second (RPS) +See the graphs in the `benchmarks` directory of the lennarb project. + +## Steps to run the benchmarks + +### 1. Install the router gem you want to test + +```bash +$ gem install lennarb +$ gem install syro +$ gem install roda +``` + +### 2. Clone the jeremyevans/r10k repository + +```bash +$ git clone https://github.com/jeremyevans/r10k +``` + +### 3. Create a new file in the `r10k` directory -![Benchmarks](../../static/rps.png) +In the `r10k` directory, create a new file called `lennarb.rb` into `builders` directory with the code below: -### Initial memory usage +```bash +$ touch r10k/builders/lennarb.rb +``` -![Benchmarks](../../static/memory.png) +Put the code below into `lennarb.rb` file: -### Runtime startup -![Benchmarks](../../static/runtime_with_startup.png) +### 4. Run the benchmarks +```bash +$ bundle exec rake benchmarks R10K_APPS="lennarb syro roda" +``` ## Conclusion diff --git a/readme.md b/readme.md index 5b4f50d..03e55c7 100644 --- a/readme.md +++ b/readme.md @@ -2,47 +2,42 @@ Lennarb is a lightweight, fast, and modular web framework for Ruby based on Rack. The **Lennarb** supports Ruby (MRI) 3.0+ -## Usage - -To use Lennarb is very simple, just create a instance of `Lennarb` and use the methods `get`, `post`, `put`, `patch` etc.. +**Basic Usage** -```rb -app = Lennarb.new +```ruby +require "lennarb" -app.get("/hello/:name") do |req, res| - name = req.params[:name] - - res.html("Hello #{name}") +Lennarb.new do |router| + router.get("/hello/:name") do |req, res| + name = req.params[:name] + res.html("Hello, #{name}!") + end end ``` -To more examples of usage see [getting started](https://aristotelesbr.github.io/lennarbguides/getting-started/index) documentation. - ## Performance -### Requests per second (RPS) - Dinamic routes +### 1. Requests per Second (RPS) -![Benchmarks](static/rps.png) +| Position | Application | 10 RPS | 100 RPS | 1.000 RPS | 10.000 RPS | +| -------- | ----------- | ---------- | ---------- | --------- | ---------- | +| 1 | Lenna | 126.252,36 | 108.086,55 | 87.111,91 | 68.460,64 | +| 2 | Roda | 123.360,37 | 88.380,56 | 66.990,77 | 48.108,29 | +| 3 | Syro | 114.105,38 | 80.909,39 | 61.415,86 | 46.639,81 | +| 4 | Hanami-API | 68.089,18 | 52.851,88 | 40.801,78 | 27.996,00 | -To more details about the benchmarks, please see the [project documentation](https://aristotelesbr.github.io/lennarb/performance/index). +This table ranks the routers by the number of requests they can process per second. Higher numbers indicate better performance. -## Documentation +Plese see [Performance](https://github.com.br/guides/performance/index) for more information. -Please see the [project documentation](https://aristotelesbr.github.io/lennarb) for more details. - -- [Getting Started](https://aristotelesbr.github.io/lennarbguides/getting-started/index) - This guide show you how to use the `lennarb` - -- [Response](https://aristotelesbr.github.io/lennarbguides/response/index) - This guide show you how to use the Response object +## Usage -## Contributing + - [Getting Started](https://github.com.br/guides/getting-started/index) - This guide covers getting up and running with **Lennarb**. -We welcome contributions to this project. + - [Performance](https://github.com.br/guides/performance/index) - The **Lennarb** is very fast. The following benchmarks were performed on a MacBook Pro (Retina, 13-inch, Early 2013) with 2,7 GHz Intel Core i7 and 8 GB 1867 MHz DDR3. Based on [jeremyevans/r10k](https://github.com/jeremyevans/r10k) using the following [template build](static/r10k/build/lennarb.rb). -1. Fork it. -2. Create your feature branch (`git checkout -b my-new-feature`). -3. Commit your changes (`git commit -am 'Add some feature'`). -4. Push to the branch (`git push origin my-new-feature`). -5. Create new Pull Request. + - [Response](https://github.com.br/guides/response/index) - This is the response guide. + The `res` object is used to send a response to the client. The Lennarb use a custom response object to send responses to the client. The `res` object is an instance of `Lennarb::Response`. ### Developer Certificate of Origin diff --git a/static/r10k/build/lennarb.rb b/static/r10k/build/lennarb.rb deleted file mode 100644 index c14b6f6..0000000 --- a/static/r10k/build/lennarb.rb +++ /dev/null @@ -1,31 +0,0 @@ -# frozen_string_literal: true - -# Released under the MIT License. -# Copyright, 2024, by Aristóteles Coutinho. - -lennarb_routes = - lambda do |f, level, prefix, calc_path, lvars| - base = BASE_ROUTE.dup - ROUTES_PER_LEVEL.times do - route = "#{prefix}#{base}" - if level == 1 - params = lvars.map { |lvar| "\#{req.params[:#{lvar}]}" } -.join('-') - f.puts " app.get '#{route}/:#{lvars.last}' do |req, res|" - f.puts " body = \"#{calc_path[1..]}#{base}-#{params}\"" - f.puts ' res.html body' - f.puts ' end' - else - lennarb_routes.call(f, level - 1, "#{route}/:#{lvars.last}/", "#{calc_path}#{base}/", lvars + [lvars.last.succ]) - end - base.succ! - end - end - -File.open("#{File.dirname(__FILE__)}/../apps/lennarb_#{LEVELS}_#{ROUTES_PER_LEVEL}.rb", 'wb') do |f| - f.puts '# frozen_string_literal: true' - f.puts "require 'lennarb'" - f.puts 'app = Lennarb.new' - lennarb_routes.call(f, LEVELS, '/', '/', ['a']) - f.puts 'App = app.freeze' -end