Skip to content

Commit

Permalink
Merge pull request #37 from aristotelesbr/development
Browse files Browse the repository at this point in the history
docs: update performance documentation
  • Loading branch information
aristotelesbr authored Jan 11, 2024
2 parents f8cfd6d + 3fa6f89 commit c69d03c
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions guides/performance/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,40 @@ $ touch r10k/builders/lennarb.rb

Put the code below into `lennarb.rb` file:

```rb

# 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
```

### 4. Run the benchmarks

Expand Down

0 comments on commit c69d03c

Please sign in to comment.