<commit_before>console.clear()

var Obs = require('../../../lib/observable')
var util = require('../../../lib/util')
var Event = require('../../../lib/event')

describe( 'set method', function() {

  var amount = 10e3

  it( 'nested fields - using set against baseline', function( done ) {
    this.timeout(50000)

    expect(function() {
      var arr = []
      var Obs2 = new Obs().$Constructor
      for( var i = 0; i < amount; i++ ) {
        arr.push( new Obs2({ i: i }) )
      }
    }).performance({
      // loop: 1,
      margin: 2.5,
      method: function() {
        var Obs2 = new Obs().$Constructor
        var arr = []
        for( var i = 0; i < amount; i++ ) {
          var obs = new Obs2()
          obs.i = new Obs2(i)
          obs.i._$key = 'i'
          obs.i._$parent = obs
          arr.push( obs )
        }
      }
    }, done )
  })

  it( 'using set against using set, with key in prototype', function( done ) {
    this.timeout(50000)
    var Obs2 = new Obs().$Constructor
    var ObsWithI = new Obs({
      i:false
    }).$Constructor

    expect( function() {
        var arr = []
        for( var i = 0; i < amount; i++ ) {
          arr.push( new ObsWithI({ i: i }) )
        }
      }).performance({
      // loop: 1,
      margin:2,
      method: function() {
        var arr = []
        for( var i = 0; i < amount; i++ ) {
          arr.push( new Obs2({ i: i }) )
        }
      }
    }, done )
  })

})

describe( 'on change emitters', function() {

  console.log('on change emitters')

  var measure = 0
  var amount = 1e3
  var instances = []

  it( 'on multiple instances', function( done ) {
    var amount = 100e3
    this.timeout(5000)
    expect(function() {
      var a = new Obs({
      $key:'a',
        $on: {
          $change:function() {
            measure++
          }
        }
      })
      var arr = instances
      var event = new Event( a )
      for( var i = 0; i < amount; i++ ) {
        arr.push( new a.$Constructor( { i: i }, event ) )
      }
      a.$emit( '$change', event )
      // expect(measure).to.equal(amount+1)
    }).performance({
      // loop: 100,
      margin:2,
      method: function() {
        var b = new Obs({<commit_msg>better perf tests<commit_after>console.clear()//do this in atom plugin

var Obs = require('../../../lib/observable')
var util = require('../../../lib/util')
var Event = require('../../../lib/event')

describe( 'set method', function() {

  var amount = 100e3

  it( 'nested fields - using set against baseline', function( done ) {
    this.timeout(50000)

    expect(function() {
      var arr = []
      var Obs2 = new Obs().$Constructor
      for( var i = 0; i < amount; i++ ) {
        arr.push( new Obs2({ i: i }) )
      }
    }).performance({
      // loop: 100,
      margin: 4,
      method: function() {
        var Obs2 = new Obs().$Constructor
        var arr = []
        for( var i = 0; i < amount; i++ ) {
          var obs = new Obs2()
          obs.i = new Obs2(i)
          obs.i._$key = 'i'
          obs.i._$parent = obs
          arr.push( obs )
        }
      }
    }, done )
  })

  it( 'using set against using set, with key in prototype', function( done ) {
    this.timeout(50000)
    var Obs2 = new Obs().$Constructor
    var ObsWithI = new Obs({
      i:false
    }).$Constructor

    expect( function() {
        var arr = []
        for( var i = 0; i < amount; i++ ) {
          arr.push( new ObsWithI({ i: i }) )
        }
      }).performance({
      // loop: 1,
      // margin:2,
      method: function() {
        var arr = []
        for( var i = 0; i < amount; i++ ) {
          arr.push( new Obs2({ i: i }) )
        }
      }
    }, done )
  })

})

describe( 'on change emitters', function() {

  console.log('on change emitters')

  var measure = 0
  var amount = 1e3
  var instances = []

  it( 'on multiple instances', function( done ) {
    var amount = 10e3
    this.timeout(5000)
    expect(function() {
      var a = new Obs({
      $key:'a',
        $on: {
          $change:function() {
            measure++
          }
        }
      })
      var arr = instances
      var event = new Event( a )
      for( var i = 0; i < amount; i++ ) {
        arr.push( new a.$Constructor( { i: i }, event ) )
      }
      a.$emit( '$change', event )
      // expect(measure).to.equal(amount+1)
    }).performance({
      // loop: 100,
      margin:2,
      method: function() {
        var b = new Obs({
{'fraction_non_alphanumeric': 0.1654320987654321, 'fraction_numerical': 0.020875420875420877, 'mean_word_length': 1.6320141760189013, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 3, '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': '3717821', 'n_tokens_mistral': 1539, 'n_tokens_neox': 1423, 'n_words': 425}