Created
April 6, 2017 03:49
-
-
Save themoriarty/69e1ab52ac0083886b1a4fe948e5eb45 to your computer and use it in GitHub Desktop.
benchmark comparison bookmarklet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:function%20tryToParse%28content%29%20%7Bconst%20lines%20%3D%20content.split%28%22%5Cn%22%29%3Blet%20header%20%3D%20undefined%3Blet%20values%20%3D%20%5B%5D%3Bfor%20%28let%20i%20%3D%200%3B%20i%20%3C%20lines.length%3B%20%2B%2Bi%29%20%7Bconst%20line%20%3D%20lines%5Bi%5D.trim%28%29%3Bif%20%28line.length%20%21%3D%200%29%20%7Bif%20%28header%20%3D%3D%3D%20undefined%29%20%7Bheader%20%3D%20line%3B%7D%20else%20%7Bconst%20match_result%20%3D%20line.match%28/%28%5CS%2B%29%5Cs%2B%28%5Cd%2B%29%20ms%5Cs%2B%5Cd%2B%20ms%5Cs%2B%5Cd%2B%5Cs%2B%5B%5Cd%5C.%5D%2B%5Cs%2Bitems%5C/s/%29%3Bif%20%28match_result%29%20%7Bvalues.push%28%7Bname%3A%20match_result%5B1%5D%2C%20%22avg%22%3A%20parseFloat%28match_result%5B2%5D%29%7D%29%3B%7D%7D%7D%7Dif%20%28header%20%21%3D%3D%20undefined%20%26%26%20values.length%20%3E%200%29%20%7Breturn%20%7Bkey%3A%20header%2C%20results%3A%20values%7D%3B%7Dreturn%20undefined%3B%7Dfunction%20getBenchmarkResults%28%29%20%7Bconst%20comments%20%3D%20document.getElementsByClassName%28%22comment-body%22%29%3Bconst%20ret%20%3D%20new%20Map%28%29%3Bfor%20%28let%20i%20%3D%200%3B%20i%20%3C%20comments.length%3B%20%2B%2Bi%29%20%7Bconst%20comment%20%3D%20comments%5Bi%5D%3Bconst%20ps%20%3D%20comment.getElementsByTagName%28%22p%22%29%3Blet%20content%20%3D%20%22%22%3Bfor%20%28let%20pi%20%3D%200%3B%20pi%20%3C%20ps.length%3B%20%2B%2Bpi%29%20%7Bif%20%28content.length%20%21%3D%200%29%20%7Bcontent%20%2B%3D%20%22%5Cn%22%3B%7Dcontent%20%2B%3D%20ps%5Bpi%5D.textContent%3B%7Dif%20%28content.length%20%21%3D%200%29%20%7Bconst%20kv%20%3D%20tryToParse%28content%29%3Bif%20%28kv%20%21%3D%3D%20undefined%29%20%7Bret.set%28kv.key%2C%20kv%29%3B%7D%7D%7Dreturn%20ret%3B%7Dfunction%20diffTest%28sideAResult%2C%20sideBResult%29%20%7Breturn%20%7Bdiff%3A%20sideBResult.avg%20-%20sideAResult.avg%2C%20sideA%3A%20sideAResult%2C%20sideB%3A%20sideBResult%7D%3B%7Dfunction%20diff%28sideA%2C%20sideB%29%20%7Bconst%20tests%20%3D%20new%20Array%28%29%3Bconst%20ret%20%3D%20%7Bname%3A%20%28sideA.key%20%2B%20%22%20vs%20%22%20%2B%20sideB.key%29%2C%20tests%3A%20tests%7D%3Bconst%20sideAResults%20%3D%20new%20Map%28sideA.results.map%28x%20%3D%3E%20%5Bx.name%2C%20x%5D%29%29%3Bconst%20sideBResults%20%3D%20new%20Map%28sideB.results.map%28x%20%3D%3E%20%5Bx.name%2C%20x%5D%29%29%3Bfor%20%28const%20test%20of%20sideAResults.keys%28%29%29%20%7Bif%20%28sideBResults.has%28test%29%29%20%7Btests.push%28%7Bname%3A%20test%2C%20results%3A%20diffTest%28sideAResults.get%28test%29%2C%20sideBResults.get%28test%29%29%7D%29%3B%7D%7Dreturn%20ret%3B%7Dfunction%20diffAll%28results%29%20%7Bconst%20keys%20%3D%20new%20Array%28%29%3Bconst%20ret%20%3D%20new%20Array%28%29%3Bfor%20%28const%20k%20of%20results.keys%28%29%29%20%7Bkeys.push%28k%29%3B%7Dfor%20%28let%20i%20%3D%200%3B%20i%20%3C%20keys.length%20-%201%3B%20%2B%2Bi%29%20%7Bfor%20%28let%20j%20%3D%20i%20%2B%201%3B%20j%20%3C%20keys.length%3B%20%2B%2Bj%29%20%7Bconst%20sideA%20%3D%20results.get%28keys%5Bi%5D%29%3Bconst%20sideB%20%3D%20results.get%28keys%5Bj%5D%29%3Bret.push%28diff%28sideA%2C%20sideB%29%29%3B%7D%7Dreturn%20ret%3B%7Dfunction%20bold%28text%2C%20doBold%29%20%7Breturn%20doBold%20%3F%20%22%2A%2A%22%20%2B%20text%20%2B%20%22%2A%2A%22%20%3A%20text%3B%7Dfunction%20toMarkdown%28results%29%20%7Blet%20ret%20%3D%20%5B%5D%3Bfor%20%28const%20singleDiff%20of%20results%29%20%7Bret.push%28%22%23%20%22%20%2B%20singleDiff.name%29%3Bret.push%28%22avg%28%25%29%20%7C%20test%20%7C%20avg%28%25%29%22%29%3Bret.push%28%22------------%20%7C%20-------------%20%7C%20-------------%22%29%3Bfor%20%28const%20test%20of%20singleDiff.tests%29%20%7Bconst%20ratio%20%3D%20Math.min%28test.results.sideA.avg%2C%20test.results.sideB.avg%29%20/%20Math.max%28test.results.sideA.avg%2C%20test.results.sideB.avg%29%3Bconst%20sideABetter%20%3D%20test.results.sideA.avg%20%3C%20test.results.sideB.avg%3Bconst%20sideBBetter%20%3D%20test.results.sideB.avg%20%3C%20test.results.sideA.avg%3Bif%20%28Math.abs%28test.results.diff%29%20/%20Math.max%28test.results.sideA.avg%2C%20test.results.sideB.avg%29%20%3E%200.05%29%20%7Bconst%20ratioA%20%3D%20test.results.sideA.avg%20%3C%20test.results.sideB.avg%20%3F%20ratio%20%3A%201%3Bconst%20ratioB%20%3D%20test.results.sideB.avg%20%3C%20test.results.sideA.avg%20%3F%20ratio%20%3A%201%3Bret.push%28bold%28test.results.sideA.avg%20%2B%20%22%20%28%22%20%2B%20%28ratioA%20%2A%20100%29.toFixed%281%29%20%2B%20%22%25%29%22%2C%20sideABetter%29%20%2B%20%22%20%7C%20%22%20%2B%20test.name%2B%20%22%20%7C%20%22%20%2B%20bold%28test.results.sideB.avg%20%2B%20%22%20%28%22%20%2B%20%28ratioB%20%2A%20100%29.toFixed%281%29%20%2B%20%22%25%29%22%2C%20sideBBetter%29%29%3B%7D%7Dret.push%28%22%22%29%3B%7Dreturn%20ret.join%28%22%5Cn%22%29%3B%7Dfunction%20main%28%29%20%7Bconst%20field%20%3D%20document.getElementById%28%22new_comment_field%22%29%3Bconst%20text%20%3D%20toMarkdown%28diffAll%28getBenchmarkResults%28%29%29%29%3Bif%20%28field.value.length%20%3D%3D%200%20%7C%7C%20true%29%20%7Bfield.value%20%3D%20text%3B%7D%20else%20%7Bfield.value%20%3D%20field.value%20%2B%20%22%5Cn%22%20%2B%20text%3B%7D%7Dmain%28%29 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment