summaryrefslogtreecommitdiff
path: root/spec/benchmarks/lib/gitlab/markdown/reference_filter_spec.rb
blob: 34cd9f7e4eb398bd64d8d65226d15bc7488767c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require 'spec_helper'

describe Gitlab::Markdown::ReferenceFilter, benchmark: true do
  let(:input) do
    html = <<-EOF
<p>Hello @alice and @bob, how are you doing today?</p>
<p>This is simple @dummy text to see how the @ReferenceFilter class performs
when @processing HTML.</p>
    EOF

    Nokogiri::HTML.fragment(html)
  end

  let(:project) { create(:empty_project) }

  let(:filter) { described_class.new(input, project: project) }

  describe '#replace_text_nodes_matching' do
    let(:iterations) { 6000 }

    describe 'with identical input and output HTML' do
      benchmark_subject do
        filter.replace_text_nodes_matching(User.reference_pattern) do |content|
          content
        end
      end

      it { is_expected.to iterate_per_second(iterations) }
    end

    describe 'with different input and output HTML' do
      benchmark_subject do
        filter.replace_text_nodes_matching(User.reference_pattern) do |content|
          '@eve'
        end
      end

      it { is_expected.to iterate_per_second(iterations) }
    end
  end
end