genObj = (defaultValue)->
	getterSetter = 'prop':
		get:()-> defaultValue
		set:(newValue)-> defaultValue = newValue
	
	generatedObject = Object.create null, getterSetter
	generatedObject.value = 'value'
	return generatedObject


new TestSuite 
	'title': 'Object Update'
	'subtitle': 'Update the value of an object property 10,000 times'
	'measureMethod': 'sync'
	'nonSharedTest': true
	'warmUps': 10000
	'timesToRun': 10000
	'setupFn': (container$)->
		@objA = genObj('value')
		@objB = genObj('value')
		currentValue = 0

		@getNewValue = ()-> "value#{currentValue++}"
		
		return

	'teardownFn': (container$)->
		delete @objA
		delete @objB
		delete @getNewValue


	'testFn': ()->
		newValue = @getNewValue()
		@objA.prop = newValue
		@objB.prop = newValue





new TestSuite 
	'title': 'Input Update'
	'subtitle': 'Update the value of an input field 10,000 times'
	'measureMethod': 'sync'
	'timesToRun': 10000
	'setupFn': (container$)->
		@obj = genObj('value')
		@input = $('<input type="text">')[0]
		currentValue = 0

		@getNewValue = ()-> "value#{currentValue++}"
		
		container$.append @input
		return

	'teardownFn': (container$)->
		container$.empty()
		delete @obj
		delete @input
		delete @getNewValue


	'testFn': ()->
		newValue = @getNewValue()
		@obj.prop = newValue
		@input.value = newValue





new TestSuite 
	'title': 'Input x100 Update'
	'subtitle': 'Update the value of 100 input fields 1,000 times'
	'measureMethod': 'sync'
	'warmUps': 100
	'timesToRun': 1000
	'setupFn': (container$)->
		currentValue = 0
		@obj = genObj('value')
		inputs = ('<input type="text">' for i in [1..100])
		@inputs$ = $(inputs.join '')

		@getNewValue = ()-> "value#{currentValue++}"
		
		container$.append @inputs$
		return

	'teardownFn': (container$)->
		container$.empty()
		delete @obj
		delete @inputs$
		delete @getNewValue


	'testFn': ()->
		newValue = @getNewValue()
		@obj.prop = newValue

		for input in @inputs$
			input.value = newValue








new TestSuite 
	'title': 'Input Transform'
	'subtitle': 'Update the value of an input field 10,000 times and apply a transform function'
	'measureMethod': 'sync'
	'timesToRun': 10000
	'setupFn': (container$)->
		@obj = genObj('value')
		@input = $('<input type="text">')[0]
		currentValue = 0

		@getNewValue = ()-> "value#{currentValue++}"
		@transform = (value)-> value.toUpperCase()
		
		container$.append @input
		return

	'teardownFn': (container$)->
		container$.empty()
		delete @input
		delete @getNewValue


	'testFn': ()->
		newValue = @transform @getNewValue()
		@obj.prop = newValue
		@input.value = newValue








new TestSuite 
	'title': 'Div HTML Update'
	'subtitle': 'Update the content of a div 10,000 times'
	'measureMethod': 'sync'
	'timesToRun': 10000
	'setupFn': (container$)->
		@obj = genObj('value')
		@div = $('<div />')[0]
		currentValue = 0

		@getNewValue = ()-> "value#{currentValue++}"
		
		container$.append @div
		return

	'teardownFn': (container$)->
		container$.empty()
		delete @obj
		delete @div
		delete @getNewValue


	'testFn': ()->
		newValue = @getNewValue()
		@obj.prop = newValue
		@div.innerHTML = newValue







new TestSuite 
	'title': 'Div HTML Same Update'
	'subtitle': 'Update the content of a div with the same value 10,000 times'
	'measureMethod': 'sync'
	'warmUps': 10000
	'timesToRun': 10000
	'setupFn': (container$)->
		@obj = genObj('value')
		@div = $('<div />')[0]
		
		container$.append @div
		return

	'teardownFn': (container$)->
		container$.empty()

		delete @obj
		delete @div
		delete @getNewValue


	'testFn': ()->
		newValue = 'value'
		@obj.prop = newValue
		@div.innerHTML = newValue








new TestSuite 
	'title': 'Div HTML Placeholder'
	'subtitle': 'Update a placeholder in the content of a div 10,000 times'
	'measureMethod': 'sync'
	'timesToRun': 10000
	'setupFn': (container$)->
		@obj = genObj('value')
		@valueOriginal = 'Content {{value}} works.'
		@div = $("<div>#{@valueOriginal}</div>")[0]
		@regEx = /\{\{value\}\}/g
		currentValue = 0

		@getNewValue = ()-> "value#{currentValue++}"
		
		container$.append @div
		return

	'teardownFn': (container$)->
		container$.empty()
		delete @div
		delete @getNewValue


	'testFn': ()->
		newValue = @getNewValue()
		@obj.prop = newValue
		@div.innerHTML = @valueOriginal.replace @regEx, ()-> newValue # Using a function instead of a value to make sure it's a fair test against SimplyBind








new TestSuite 
	'title': 'Div HTML 250 Placeholders'
	'subtitle': 'Update 250 placeholders in the content of a div 1,000 times'
	'measureMethod': 'sync'
	'warmUps': 100
	'timesToRun': 1000
	'setupFn': (container$)->
		@obj = genObj('value')
		@valueOriginal = '{{value}} '.repeat(250)
		@div = $("<div>#{@valueOriginal}</div>")[0]
		@regEx = /\{\{value\}\}/g
		currentValue = 0

		@getNewValue = ()-> "value#{currentValue++}"
		
		container$.append @div
		return

	'teardownFn': (container$)->
		container$.empty()
		delete @div
		delete @getNewValue


	'testFn': ()->
		newValue = @getNewValue()
		@obj.prop = newValue
		@div.innerHTML = @valueOriginal.replace @regEx, ()-> newValue # Using a function instead of a value to make sure it's a fair test against SimplyBind








new TestSuite 
	'title': 'Div Text Update'
	'subtitle': 'Update the textContent of a div 10,000 times'
	'measureMethod': 'sync'
	'timesToRun': 10000
	'setupFn': (container$)->
		@obj = genObj('value')
		@div = $('<div />')[0]
		currentValue = 0

		@getNewValue = ()-> "value#{currentValue++}"
		
		container$.append @div
		return

	'teardownFn': (container$)->
		container$.empty()
		delete @div
		delete @getNewValue


	'testFn': ()->
		newValue = @getNewValue()
		@obj.prop = newValue
		@div.textContent = newValue









new TestSuite 
	'title': 'Div Text Placeholder'
	'subtitle': 'Update a placeholder in the textContent of a div 10,000 times'
	'measureMethod': 'sync'
	'timesToRun': 10000
	'setupFn': (container$)->
		@obj = genObj('value')
		@div = $('<div />')[0]
		currentValue = 0

		@getNewValue = ()-> "value#{currentValue++}"
		
		container$.append @div
		return

	'teardownFn': (container$)->
		container$.empty()
		delete @div
		delete @getNewValue


	'testFn': ()->
		placeholder = 'Content {{value}} works.'
		newValue = @getNewValue()
		@obj.prop = newValue
		@div.textContent = placeholder.replace '{{value}}', newValue








new TestSuite 
	'title': 'Create 1k DOM Els'
	'subtitle': 'Create 1000 elements from array & insert into a div'
	'measureMethod': 'sync'
	'warmUps': 10
	'timesToRun': 10
	'setupFn': (container$)->
		@obj = 'divs':[]		
		@container$ = container$

		return

	'teardownFn': (container$)->
		container$.empty()

		delete @obj.divs
		delete @obj


	'testFn': ()->
		@obj.divs = (i for i in [1..1000])
		newInnerHTML = ''
		newInnerHTML += "<div>#{value}</div>" for value in @obj.divs
		@container$[0].innerHTML = newInnerHTML







new TestSuite 
	'title': 'Update 1k DOM Els'
	'subtitle': 'Update 1000 existing elements 100 times'
	'measureMethod': 'sync'
	# 'warmUps': 10
	'timesToRun': 100
	'setupFn': (container$)->
		@obj = genObj('value')
		@container = container$[0]
		currentValue = 0
		
		@getNewValue = ()-> "value#{currentValue++}"
		
		divs = (i for i in [1..1000])
		newInnerHTML = ''
		newInnerHTML += "<div>#{value}</div>" for value in divs
		container$[0].innerHTML = newInnerHTML


	'teardownFn': (container$)->
		container$.empty()

		delete @obj.divs
		delete @obj
		delete @getNewValue


	'testFn': ()->
		newValue = @getNewValue()
		@obj.prop = newValue
		
		for div in @container.children
			div.textContent = newValue







# new TestSuite 
# 	'title': 'String replace - string'
# 	'subtitle': ''
# 	'measureMethod': 'sync'
# 	'nonSharedTest':true
# 	'warmUps': 10000
# 	'timesToRun': 10000
# 	'setupFn': (container$)->
# 		@string = 'This value needs some {{replacement}} done on it, which will cause {{replacement}} to be replaced with {{replacement}} with no worries in regards to {{replacement}}'
# 		@replaceBy = '{{replacement}}'
# 		@target = '{{replacement}}'
		
# 		@getNewValue = ()->
# 			currentValue = !currentValue
# 			return if currentValue then 'valueA' else 'valueB'
		

# 	'teardownFn': (container$)->
# 		delete @string
# 		delete @getNewValue


# 	'testFn': ()->
# 		newString = @string
# 		newValue = @getNewValue()
	
# 		while newString.indexOf(@target) isnt -1
# 			newString = newString.replace(@replaceBy, newValue)







# new TestSuite 
# 	'title': 'String replace - split'
# 	'subtitle': ''
# 	'measureMethod': 'sync'
# 	'nonSharedTest':true
# 	'warmUps': 10000
# 	'timesToRun': 10000
# 	'setupFn': (container$)->
# 		@string = 'This value needs some {{replacement}} done on it, which will cause {{replacement}} to be replaced with {{replacement}} with no worries in regards to {{replacement}}'
# 		@replaceBy = '{{replacement}}'
# 		@target = '{{replacement}}'
		
# 		@getNewValue = ()->
# 			currentValue = !currentValue
# 			return if currentValue then 'valueA' else 'valueB'
		

# 	'teardownFn': (container$)->
# 		delete @string
# 		delete @getNewValue


# 	'testFn': ()->
# 		newString = @string
# 		newValue = @getNewValue()
# 		newString = newString.split(@replaceBy).join(newValue)








# new TestSuite 
# 	'title': 'String replace - regEx'
# 	'subtitle': ''
# 	'measureMethod': 'sync'
# 	'nonSharedTest':true
# 	'warmUps': 10000
# 	'timesToRun': 10000
# 	'setupFn': (container$)->
# 		@string = 'This value needs some {{replacement}} done on it, which will cause {{replacement}} to be replaced with {{replacement}} with no worries in regards to {{replacement}}'
# 		@replaceBy = /\{\{replacement\}\}/
# 		@target = '{{replacement}}'
		
# 		@getNewValue = ()->
# 			currentValue = !currentValue
# 			return if currentValue then 'valueA' else 'valueB'
		

# 	'teardownFn': (container$)->
# 		delete @string
# 		delete @getNewValue


# 	'testFn': ()->
# 		newString = @string
# 		newValue = @getNewValue()
	
# 		while newString.indexOf(@target) isnt -1
# 			newString = newString.replace(@replaceBy, newValue)







# new TestSuite 
# 	'title': 'String replace - regEx Global'
# 	'subtitle': ''
# 	'measureMethod': 'sync'
# 	'nonSharedTest':true
# 	'warmUps': 10000
# 	'timesToRun': 10000
# 	'setupFn': (container$)->
# 		@string = 'This value needs some {{replacement}} done on it, which will cause {{replacement}} to be replaced with {{replacement}} with no worries in regards to {{replacement}}'
# 		@replaceBy = /\{\{replacement\}\}/g
# 		@target = '{{replacement}}'
		
# 		@getNewValue = ()->
# 			currentValue = !currentValue
# 			return if currentValue then 'valueA' else 'valueB'
		

# 	'teardownFn': (container$)->
# 		delete @string
# 		delete @getNewValue


# 	'testFn': ()->
# 		newString = @string
# 		newValue = @getNewValue()
# 		newString = newString.replace(@replaceBy, newValue)







# new TestSuite 
# 	'title': 'String replace - regEx Global Func'
# 	'subtitle': ''
# 	'measureMethod': 'sync'
# 	'nonSharedTest':true
# 	'warmUps': 10000
# 	'timesToRun': 10000
# 	'setupFn': (container$)->
# 		@string = 'This value needs some {{replacement}} done on it, which will cause {{replacement}} to be replaced with {{replacement}} with no worries in regards to {{replacement}}'
# 		@replaceBy = /\{\{replacement\}\}/g
# 		@target = '{{replacement}}'
		
# 		@getNewValue = ()->
# 			currentValue = !currentValue
# 			return if currentValue then 'valueA' else 'valueB'
		

# 	'teardownFn': (container$)->
# 		delete @string
# 		delete @getNewValue


# 	'testFn': ()->
# 		newString = @string
# 		newValue = @getNewValue()
# 		newString = newString.replace(@replaceBy, ()-> newValue)







# new TestSuite 
# 	'title': 'matchless replace - string'
# 	'subtitle': ''
# 	'measureMethod': 'sync'
# 	'nonSharedTest':true
# 	'warmUps': 10000
# 	'timesToRun': 10000
# 	'setupFn': (container$)->
# 		@string = 'This value needs some replacement done on it, which will cause replacement to be replaced with replacement with no worries in regards to replacement'
# 		@replaceBy = '{{replacement}}'
# 		@target = '{{replacement}}'
		
# 		@getNewValue = ()->
# 			currentValue = !currentValue
# 			return if currentValue then 'valueA' else 'valueB'
		

# 	'teardownFn': (container$)->
# 		delete @string
# 		delete @getNewValue


# 	'testFn': ()->
# 		newString = @string
# 		newValue = @getNewValue()
	
# 		while newString.indexOf(@target) isnt -1
# 			newString = newString.replace(@replaceBy, newValue)







# new TestSuite 
# 	'title': 'matchless replace - split'
# 	'subtitle': ''
# 	'measureMethod': 'sync'
# 	'nonSharedTest':true
# 	'warmUps': 10000
# 	'timesToRun': 10000
# 	'setupFn': (container$)->
# 		@string = 'This value needs some replacement done on it, which will cause replacement to be replaced with replacement with no worries in regards to replacement'
# 		@replaceBy = '{{replacement}}'
# 		@target = '{{replacement}}'
		
# 		@getNewValue = ()->
# 			currentValue = !currentValue
# 			return if currentValue then 'valueA' else 'valueB'
		

# 	'teardownFn': (container$)->
# 		delete @string
# 		delete @getNewValue


# 	'testFn': ()->
# 		newString = @string
# 		newValue = @getNewValue()
# 		newString = newString.split(@replaceBy).join(newValue)








# new TestSuite 
# 	'title': 'matchless replace - regEx'
# 	'subtitle': ''
# 	'measureMethod': 'sync'
# 	'nonSharedTest':true
# 	'warmUps': 10000
# 	'timesToRun': 10000
# 	'setupFn': (container$)->
# 		@string = 'This value needs some replacement done on it, which will cause replacement to be replaced with replacement with no worries in regards to replacement'
# 		@replaceBy = /\{\{replacement\}\}/
# 		@target = '{{replacement}}'
		
# 		@getNewValue = ()->
# 			currentValue = !currentValue
# 			return if currentValue then 'valueA' else 'valueB'
		

# 	'teardownFn': (container$)->
# 		delete @string
# 		delete @getNewValue


# 	'testFn': ()->
# 		newString = @string
# 		newValue = @getNewValue()
	
# 		while newString.indexOf(@target) isnt -1
# 			newString = newString.replace(@replaceBy, newValue)







# new TestSuite 
# 	'title': 'matchless replace - regEx Global'
# 	'subtitle': ''
# 	'measureMethod': 'sync'
# 	'nonSharedTest':true
# 	'warmUps': 10000
# 	'timesToRun': 10000
# 	'setupFn': (container$)->
# 		@string = 'This value needs some replacement done on it, which will cause replacement to be replaced with replacement with no worries in regards to replacement'
# 		@replaceBy = /\{\{replacement\}\}/g
# 		@target = '{{replacement}}'
		
# 		@getNewValue = ()->
# 			currentValue = !currentValue
# 			return if currentValue then 'valueA' else 'valueB'
		

# 	'teardownFn': (container$)->
# 		delete @string
# 		delete @getNewValue


# 	'testFn': ()->
# 		newString = @string
# 		newValue = @getNewValue()
# 		newString = newString.replace(@replaceBy, newValue)







# new TestSuite 
# 	'title': 'matchless replace - regEx Global Func'
# 	'subtitle': ''
# 	'measureMethod': 'sync'
# 	'nonSharedTest':true
# 	'warmUps': 10000
# 	'timesToRun': 10000
# 	'setupFn': (container$)->
# 		@string = 'This value needs some replacement done on it, which will cause replacement to be replaced with replacement with no worries in regards to replacement'
# 		@replaceBy = /\{\{replacement\}\}/g
# 		@target = '{{replacement}}'
		
# 		@getNewValue = ()->
# 			currentValue = !currentValue
# 			return if currentValue then 'valueA' else 'valueB'
		

# 	'teardownFn': (container$)->
# 		delete @string
# 		delete @getNewValue


# 	'testFn': ()->
# 		newString = @string
# 		newValue = @getNewValue()
# 		newString = newString.replace(@replaceBy, ()-> newValue)




























