github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/images/benchmarks/ruby/main.rb (about)

     1  require "sinatra"
     2  require "securerandom"
     3  require "redis"
     4  
     5  redis_host = ENV["HOST"]
     6  $redis = Redis.new(host: redis_host)
     7  
     8  def generateText
     9      for i in 0..99
    10          $redis.set(i, randomBody(1024))
    11      end
    12  end
    13  
    14  def randomBody(length)
    15      return SecureRandom.alphanumeric(length)
    16  end
    17  
    18  generateText
    19  template = ERB.new(File.read('./index.erb'))
    20  
    21  get "/" do
    22      texts = Array.new
    23      for i in 0..4
    24          texts.push($redis.get(rand(0..99)))
    25      end
    26      template.result_with_hash(text: texts)
    27  end