<commit_before>module Midori::Server
  attr_accessor :request, :api, :websocket, :eventsource

  def initialize(api)
    @api = api
    @request = Midori::Request.new
    @websocket = Midori::WebSocket.new(self)
    @eventsource = Midori::EventSource.new(self)
  end

  def receive_data(data)
    ->() {async_internal(Fiber.new do
      start_time = Time.now
      data = StringIO.new(data)
      port, ip = Socket.unpack_sockaddr_in(get_peername)
      @request.ip = ip
      @request.port = port
      if @request.parsed?
        websocket_request(data)
      else
        receive_new_request(data)
      end
      puts "#{@request.ip} - - [#{Time.now.inspect}] \"#{@request.method} #{@request.path} #{@request.protocol}\" #{@response.status} #{(Time.now.to_f - start_time.to_f).round(5)}".green
    end)}.call
  end

  def receive_new_request(data)
    begin
      @request.parse(data)
      @response = @api.receive(request, self)
      call_event(:open) if @request.websocket?
    rescue Midori::Error::NotFound => _e<commit_msg>Improve performance by inspect now time for only once<commit_after>module Midori::Server
  attr_accessor :request, :api, :websocket, :eventsource

  def initialize(api)
    @api = api
    @request = Midori::Request.new
    @websocket = Midori::WebSocket.new(self)
    @eventsource = Midori::EventSource.new(self)
  end

  def receive_data(data)
    ->() {async_internal(Fiber.new do
      start_time = Time.now
      data = StringIO.new(data)
      port, ip = Socket.unpack_sockaddr_in(get_peername)
      @request.ip = ip
      @request.port = port
      if @request.parsed?
        websocket_request(data)
      else
        receive_new_request(data)
      end
      now_time = Time.now
      puts "#{@request.ip} - - [#{now_time.inspect}] \"#{@request.method} #{@request.path} #{@request.protocol}\" #{@response.status} #{(now_time.to_f - start_time.to_f).round(5)}".green
    end)}.call
  end

  def receive_new_request(data)
    begin
      @request.parse(data)
      @response = @api.receive(request, self)
      call_event(:open) if @request.websocket?
    rescue Midori::Error::NotFound => _e
{'fraction_non_alphanumeric': 0.13964386129334583, 'fraction_numerical': 0.0009372071227741331, 'mean_word_length': 3.227722772277228, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4084970', 'n_tokens_mistral': 732, 'n_tokens_neox': 724, 'n_words': 135}