<commit_before>require './benchmark-helper'
{$, _, RootView} = require 'atom'
TokenizedBuffer = require '../src/tokenized-buffer'

describe "editor.", ->
  editor = null

  beforeEach ->
    window.rootViewParentSelector = '#jasmine-content'
    window.rootView = new RootView
    window.rootView.attachToDom()

    rootView.width(1024)
    rootView.height(768)
    rootView.open() # open blank editor
    editor = rootView.getActiveView()

  afterEach ->
    if editor.pendingDisplayUpdate
      waitsFor "editor to finish rendering", (done) ->
        editor.on 'editor:display-updated', done

  describe "keymap.", ->
    event = null

    beforeEach ->
      event = keydownEvent('x', target: editor.hiddenInput[0])

    benchmark "keydown-event-with-no-binding", 10, ->
      keymap.handleKeyEvent(event)

  describe "opening-buffers.", ->
    benchmark "300-line-file.", ->
      buffer = project.bufferForPath('medium.coffee')

  describe "empty-file.", ->
    benchmark "insert-delete", ->
      editor.insertText('x')
      editor.backspace()

  describe "300-line-file.", ->
    beforeEach ->
      rootView.open('medium.coffee')

    describe "at-begining.", ->
      benchmark "insert-delete", ->
        editor.insertText('x')
        editor.backspace()

      benchmark "insert-delete-rehighlight", ->
        editor.insertText('"')
        editor.backspace()

    describe "at-end.", ->
      beforeEach ->
        editor.moveCursorToBottom()

      benchmark "insert-delete", ->
        editor.insertText('"')
        editor.backspace()

    fdescribe "calculating-pixel-position.", ->
      line = null
      beforeEach ->
        editor.scrollTop(2000)
        editor.resetDisplay()
        line = editor.lineElementForScreenRow(106)[0]

      benchmark "positionLeftForLineAndColumn", 20000, ->
        editor.positionLeftForLineAndColumn(line, 82)
        editor.pixelLeftCache.delete(line)

      benchmark "positionLeftForLineAndColumn.cached", 20000, ->
        editor.positionLeftForLineAndColumn(line, 82)

    describe "text-rendering.", ->
      beforeEach ->
        editor.scrollTop(2000)

      benchmark "resetDisplay", 50, ->
        editor.resetDisplay()

      benchmark "htmlForScreenRows", 50, ->
        lastRow = editor.getLastScreenRow()
        editor.htmlForScreenRows(0, lastRow)
<commit_msg>Get a few benchmarks in there<commit_after>require './benchmark-helper'
{$, _, RootView} = require 'atom'
TokenizedBuffer = require '../src/tokenized-buffer'

describe "editor.", ->
  editor = null

  beforeEach ->
    window.rootViewParentSelector = '#jasmine-content'
    window.rootView = new RootView
    window.rootView.attachToDom()

    rootView.width(1024)
    rootView.height(768)
    rootView.open() # open blank editor
    editor = rootView.getActiveView()

  afterEach ->
    if editor.pendingDisplayUpdate
      waitsFor "editor to finish rendering", (done) ->
        editor.on 'editor:display-updated', done

  describe "keymap.", ->
    event = null

    beforeEach ->
      event = keydownEvent('x', target: editor.hiddenInput[0])

    benchmark "keydown-event-with-no-binding", 10, ->
      keymap.handleKeyEvent(event)

  describe "opening-buffers.", ->
    benchmark "300-line-file.", ->
      buffer = project.bufferForPath('medium.coffee')

  describe "empty-file.", ->
    benchmark "insert-delete", ->
      editor.insertText('x')
      editor.backspace()

  describe "300-line-file.", ->
    beforeEach ->
      rootView.open('medium.coffee')

    describe "at-begining.", ->
      benchmark "insert-delete", ->
        editor.insertText('x')
        editor.backspace()

      benchmark "insert-delete-rehighlight", ->
        editor.insertText('"')
        editor.backspace()

    describe "at-end.", ->
      beforeEach ->
        editor.moveCursorToBottom()

      benchmark "insert-delete", ->
        editor.insertText('"')
        editor.backspace()

    describe "positionLeftForLineAndColumn.", ->
      line = null
      beforeEach ->
        editor.scrollTop(2000)
        editor.resetDisplay()
        line = editor.lineElementForScreenRow(106)[0]

      describe "one-line.", ->
        beforeEach ->
          editor.clearCharacterWidthCache()

        benchmark "uncached", 5000, ->
          editor.positionLeftForLineAndColumn(line, 106, 82)
          editor.clearCharacterWidthCache()

        benchmark "cached", 5000, ->
          editor.positionLeftForLineAndColumn(line, 106, 82)

      describe "multiple-lines.", ->
        [firstRow, lastRow] = []
        beforeEach ->
          firstRow = editor.getFirstVisibleScreenRow()
          lastRow = editor.getLastVisibleScreenRow()

        benchmark "cache-entire-visible-area", 100, ->
          for i in [firstRow..lastRow]
            line = editor.lineElementForScreenRow(i)[0]
            editor.positionLeftForLineAndColumn(line, i, Math.max(0, editor.lineLengthForBufferRow(i)))

    describe "text-rendering.", ->
      beforeEach ->
        editor.scrollTop(2000)

      benchmark "resetDisplay", 50, ->
        editor.resetDisplay()

      benchmark "htmlForScreenRows", 50, ->
        lastRow = editor.getLastScreenRow()
        editor.htmlForScreenRows(0, lastRow)

{'fraction_non_alphanumeric': 0.1325139235644325, 'fraction_numerical': 0.019781063952371808, 'mean_word_length': 2.636871508379888, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 62, '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': '949630', 'n_tokens_mistral': 1620, 'n_tokens_neox': 1484, 'n_words': 275}