How to use setupBenchmark method in pytest-benchmark

Best Python code snippet using pytest-benchmark

zip.js

Source:zip.js Github

copy

Full Screen

1suite("Zip", function() {2 var assert;3 var benchmark;4 var fileLoader;5 setup(function(done) {6 requirejs(["assert", "benchmark", "Model/FileLoader"], function(Assert, Benchmark, FileLoader) {7 assert = Assert;8 benchmark = Benchmark;9 fileLoader = new FileLoader();10 fileLoader.load("Functions", "library");11 fileLoader.load("nzipcees", "test");12 done();13 });14 });15 suite("| Zip and nZip", function() {16 /**17 * Test case for binary zip, add two vectors.18 *19 * @input binaryZip([1,2,3], [4,5,6], add)20 * @expected [5,7,9]21 */22 test("| BinaryZip: add two vectors", function() {23 eval(fileLoader.getContent());24 setUpAddTwoVectors();25 output = binaryZip(input1, input2, add);26 assert.deepEqual(output, expected);27 });28 /**29 * Test case for multiary zip, add two vectors.30 *31 * @input multiaryZip([[1,2,3], [4,5,6]], add)32 * @expected [5,7,9]33 */34 test("| MultiaryZip: add two vectors", function() {35 eval(fileLoader.getContent());36 setUpAddTwoVectors();37 output = multiaryZip([input1, input2], add);38 assert.deepEqual(output, expected);39 });40 /**41 * Test case for zip, add two vectors.42 *43 * @input zip([[1,2,3], [4,5,6]], add)44 * @expected [5,7,9]45 */46 test("| Zip: add two vectors", function() {47 eval(fileLoader.getContent());48 setUpAddTwoVectors();49 output = zip([input1, input2], add);50 assert.deepEqual(output, expected);51 });52 //----------------------------------------------------------------------53 /**54 * Test case for binary zip, add scalar to vector.55 *56 * @input binaryZip([1, 1, [1, 1, [1, 1]]], 1, add)57 * @expected [2, 2, [2, 2, [2, 2]]]58 */59 test("| BinaryZip: add scalar to vector", function() {60 eval(fileLoader.getContent());61 setUpAddScalarToVector();62 output = binaryZip(input1, input2, add);63 assert.deepEqual(output, expected);64 });65 /**66 * Test case for multiary zip, add scalar to vector.67 *68 * @input multiaryZip([[1, 1, [1, 1, [1, 1]]], 1], add)69 * @expected [2, 2, [2, 2, [2, 2]]]70 */71 test("| MultiaryZip: add scalar to vector", function() {72 eval(fileLoader.getContent());73 setUpAddScalarToVector();74 output = multiaryZip([input1, input2], add);75 assert.deepEqual(output, expected);76 });77 /**78 * Test case for zip, add scalar to vector.79 *80 * @input zip([[1, 1, [1, 1, [1, 1]]], 1], add)81 * @expected [2, 2, [2, 2, [2, 2]]]82 */83 test("| Zip: add scalar to vector", function() {84 eval(fileLoader.getContent());85 setUpAddScalarToVector();86 output = zip([input1, input2], add);87 assert.deepEqual(output, expected);88 });89 //----------------------------------------------------------------------90 /**91 * Test case for binaryZip, add vector to nested vector.92 *93 * @input binaryzip([1, 1, [1, 1, [1, 1, 1]]], [1, 1, 1, 1], add)94 * @expected [2, 2, [2, 2, [2, 2, 2]]]95 */96 test("| BinaryZip: add vector to nested vector", function() {97 eval(fileLoader.getContent());98 setUpAddVectorToNestedVector();99 output = binaryZip(input1, input2, add);100 assert.deepEqual(output, expected);101 });102 /**103 * Test case for multiaryZip, add vector to nested vector.104 *105 * @input multiaryzip([[1, 1, [1, 1, [1, 1, 1]]], [1, 1, 1, 1]], add)106 * @expected [2, 2, [2, 2, [2, 2, 2]]]107 */108 test("| MultiaryZip: add vector to nested vector", function() {109 eval(fileLoader.getContent());110 setUpAddVectorToNestedVector();111 output = multiaryZip([input1, input2], add);112 assert.deepEqual(output, expected);113 });114 /**115 * Test case for zip, add vector to nested vector.116 *117 * @input zip([[1, 1, [1, 1, [1, 1, 1]]], [1, 1, 1, 1]], add)118 * @expected [2, 2, [2, 2, [2, 2, 2]]]119 */120 test("| Zip: add vector to nested vector", function() {121 eval(fileLoader.getContent());122 setUpAddVectorToNestedVector();123 output = zip([input1, input2], add);124 assert.deepEqual(output, expected);125 });126 //----------------------------------------------------------------------127 /**128 * Test case for binary zip, add nested vector to nested vector.129 *130 * @input zip([1, 1, [1, 1, [1, 1, 1]]], [1, 1, [1, 1, [1, 1]], 1] , add)131 * @expected [2, 2, [2, 2, [2, 2]]]132 */133 test("| BinaryZip: add two nested vectors", function() {134 eval(fileLoader.getContent());135 setUpAddTwoNestedVectors();136 output = binaryZip(input1, input2, add);137 assert.deepEqual(output, expected);138 });139 /**140 * Test case for multiary zip, add nested vector to nested vector.141 *142 * @input multiaryZip([[1, 1, [1, 1, [1, 1, 1]]], [1, 1, [1, 1, [1, 1]], 1]] , add)143 * @expected [2, 2, [2, 2, [2, 2]]]144 */145 test("| MultiaryZip: add two nested vectors", function() {146 eval(fileLoader.getContent());147 setUpAddTwoNestedVectors();148 output = multiaryZip([input1, input2], add);149 assert.deepEqual(output, expected);150 });151 /**152 * Test case for zip, add nested vector to nested vector.153 *154 * @input Zip([[1, 1, [1, 1, [1, 1, 1]]], [1, 1, [1, 1, [1, 1]], 1]] , add)155 * @expected [2, 2, [2, 2, [2, 2]]]156 */157 test("| Zip: add two nested vectors", function() {158 eval(fileLoader.getContent());159 setUpAddTwoNestedVectors();160 output = zip([input1, input2], add);161 assert.deepEqual(output, expected);162 });163 //----------------------------------------------------------------------164 /**165 * Test case for zip().166 *167 * @input zip([[1,2,3],[4,5,6],[7,8,9]], sum)168 * @expected [12,15,18]169 */170 test("| Zip: sum three vectors", function() {171 eval(fileLoader.getContent());172 input1 = [1, 2, 3];173 input2 = [4, 5, 6];174 input3 = [7, 8, 9];175 expected = [12, 15, 18];176 output = zip([input1, input2, input3], sum);177 assert.deepEqual(output, expected);178 });179 //----------------------------------------------------------------------180 /**181 * Test case for zip().182 *183 * @input zip([[1, 1, [1, 1, [1, 1, 1]]], [1, 1, [1, 1, [1, 1]], 1], 2], sum)184 * @expected [4, 4, [4, 4, [4, 4]]]185 */186 test("| Zip: sum scalar to two nested vectors", function() {187 eval(fileLoader.getContent());188 input1 = [1, 1, [1, 1, [1, 1, 1]]];189 input2 = [1, 1, [1, 1, [1, 1]], 1];190 input3 = 2;191 expected = [4, 4, [4, 4, [4, 4]]];192 output = zip([input1, input2, input3], sum);193 assert.deepEqual(output, expected);194 });195 //----------------------------------------------------------------------196 /**197 * Test case for zip().198 *199 * @input zip([[1, 1, [1, 1, [1, 1, 1]]], [1, 1, [1, 1, [1, 1]], 1], [2, 2, 2, 2]], sum)200 * @expected [4, 4, [4, 4, [4, 4]]]201 */202 test("| Zip: sum vector to two nested vectors", function() {203 eval(fileLoader.getContent());204 input1 = [1, 1, [1, 1, [1, 1, 1]]];205 input2 = [1, 1, [1, 1, [1, 1]], 1];206 input3 = [2, 2, 2, 2];207 expected = [4, 4, [4, 4, [4, 4]]];208 output = zip([input1, input2, input3], sum);209 assert.deepEqual(output, expected);210 });211 //----------------------------------------------------------------------212 /**213 * Test case for zip().214 *215 * @input zip([[1, 1, [1, 1, [1, 1, 1]]], [1, 1, [1, 1, [1, 1]], 1], [2, 2, [2, 2]]], sum)216 * @expected [4, 4, [4, 4]]217 */218 test("| Zip: sum vector to two nested vectors", function() {219 eval(fileLoader.getContent());220 input1 = [1, 1, [1, 1, [1, 1, 1]]];221 input2 = [1, 1, [1, 1, [1, 1]], 1];222 input3 = [2, 2, [2, 2]];223 expected = [4, 4, [4, 4]];224 output = zip([input1, input2, input3], sum);225 assert.deepEqual(output, expected);226 });227 //----------------------------------------------------------------------228 var testAddTwoVectorsLength1 = "@benchmark: add two vectors of length 1";229 test(testAddTwoVectorsLength1, function() {230 var input1 = RandomNumberArray(1, 1000, 1);231 var input2 = RandomNumberArray(1, 1000, 1);232 var args = [input1, input2];233 setUpBenchmark(testAddTwoVectorsLength1, args);234 });235 var testAddTwoVectorsLength10 = "@benchmark: add two vectors of length 10";236 test(testAddTwoVectorsLength10, function() {237 var input1 = RandomNumberArray(1, 1000, 10);238 var input2 = RandomNumberArray(1, 1000, 10);239 var args = [input1, input2];240 setUpBenchmark(testAddTwoVectorsLength10, args);241 });242 var testAddTwoVectorsLength100 = "@benchmark: add two vectors of length 100";243 test(testAddTwoVectorsLength100, function() {244 var input1 = RandomNumberArray(1, 1000, 100);245 var input2 = RandomNumberArray(1, 1000, 100);246 var args = [input1, input2];247 setUpBenchmark(testAddTwoVectorsLength100, args);248 });249 //----------------------------------------------------------------------250 var testAddTwoNestedVectorsLength1 = "@benchmark: add two nested vectors of length 1";251 test(testAddTwoNestedVectorsLength1, function() {252 var input1 = RandomNumberArrayNested(1, 1000, 1, 1, 1);253 var input2 = RandomNumberArrayNested(1, 1000, 1, 1, 1);254 var args = [input1, input2];255 setUpBenchmark(testAddTwoNestedVectorsLength1, args);256 });257 var testAddTwoNestedVectorsLength5 = "@benchmark: add two nested vectors of length 5";258 test(testAddTwoNestedVectorsLength5, function() {259 var input1 = RandomNumberArrayNested(1, 1000, 5, 5, 5);260 var input2 = RandomNumberArrayNested(1, 1000, 5, 5, 5);261 var args = [input1, input2];262 setUpBenchmark(testAddTwoNestedVectorsLength5, args);263 });264 //----------------------------------------------------------------------265 var testAddOneNestedVectorsLength1 = "@benchmark: add one nested vectors of length 1";266 test(testAddOneNestedVectorsLength1, function() {267 var args = RandomNumberArrayNested(1, 1000, 1, 1, 1);268 setUpBenchmark(testAddOneNestedVectorsLength1, args);269 });270 var testAddFourNestedVectorsLength5 = "@benchmark: add four nested vectors of length 5";271 test(testAddFourNestedVectorsLength5, function() {272 var args = RandomNumberArrayNested(1, 1000, 5, 4, 3);273 setUpBenchmark(testAddFourNestedVectorsLength5, args);274 });275 var testAddFiveNestedVectorsLength5 = "@benchmark: add five nested vectors of length 5";276 test(testAddFiveNestedVectorsLength5, function() {277 var args = RandomNumberArrayNested(1, 1000, 5, 5, 1);278 setUpBenchmark(testAddFiveNestedVectorsLength5, args);279 });280 var testAddTenNestedVectorsLength10 = "@benchmark: add ten nested vectors of length 10";281 test(testAddTenNestedVectorsLength10, function() {282 var args = RandomNumberArrayNested(1, 1000, 10, 10, 1);283 setUpBenchmark(testAddTenNestedVectorsLength10, args);284 });285 });286 function setUpAddTwoVectors() {287 input1 = [1, 2, 3];288 input2 = [4, 5, 6];289 expected = [5, 7, 9];290 }291 function setUpAddScalarToVector() {292 input1 = [1, 1, [1, 1, [1, 1]]];293 input2 = 1;294 expected = [2, 2, [2, 2, [2, 2]]];295 }296 function setUpAddVectorToNestedVector() {297 input1 = [1, 1, [1, 1, [1, 1, 1]]];298 input2 = [1, 1, 1, 1];299 expected = [2, 2, [2, 2, [2, 2, 2]]];300 }301 function setUpAddTwoNestedVectors() {302 input1 = [1, 1, [1, 1, [1, 1, 1]]];303 input2 = [1, 1, [1, 1, [1, 1]], 1];304 expected = [2, 2, [2, 2, [2, 2]]];305 }306 function setUpBenchmark(name, args) {307 console.log(name);308 eval(fileLoader.getContent());309 var benchmark_suite = new benchmark.Suite();310 var func = sum;311 var funcCees = sumCees;312 // add tests313 if (args.length === 2) {314 func = add;315 funcCees = addCees;316 benchmark_suite317 .add('binaryZip()', function() {318 binaryZip(args[0], args[1], func);319 });320 }321 benchmark_suite322 .add('multiaryZip()', function() {323 multiaryZip(args, func);324 })325 .add('nzipcees()', function() {326 nzipcees(args, funcCees);327 })328 // add listeners329 .on('cycle', function(event) {330 console.log(String(event.target));331 })332 .on('complete', function() {333 console.log('Fastest is %s', this.filter('fastest').pluck('name'));334 assert.equal(this.filter('slowest').pluck('name'), "nzipcees()");335 })336 // run async337 .run({338 'async': false339 });340 }341});342/*343 * Return a random number between min and max.344 */345function RandomNumber(min, max) {346 return (Math.round((max - min) * Math.random() + min));347}348/*349 * Total elements:350 * numElements351 */352function RandomNumberArray(min, max, numElements) {353 var _array = [];354 for (var i = 0; i < numElements; i++) {355 _array[i] = RandomNumber(min, max);356 }357 return _array;358}359/*360 * Total elements:361 * numBranches^depth + (numElements - numBranches) * Sum[numBranches^i, {i, 0 , depth}]362 */363function RandomNumberArrayNested(min, max, numElements, numBranches, depth) {364 var _array = RandomNumberArray(min, max, numElements);365 if (depth === 0) {366 return _array;367 } else {368 for (var i = 0; i < numBranches; i++) {369 _array[i] = RandomNumberArrayNested(min, max, numElements, numBranches, depth - 1);370 }371 return _array;372 }...

Full Screen

Full Screen

benchmark_run_unittest.py

Source:benchmark_run_unittest.py Github

copy

Full Screen

...53 def __init__(self, page_set):54 super(FailingPage, self).__init__(page_set)55 self.RunNavigateSteps.side_effect = Exception('Deliberate exception')56class BenchmarkRunTest(unittest.TestCase):57 def setupBenchmark(self):58 finder_options = fakes.CreateBrowserFinderOptions()59 finder_options.browser_options.platform = fakes.FakeLinuxPlatform()60 finder_options.output_formats = ['none']61 finder_options.suppress_gtest_report = True62 finder_options.output_dir = None63 finder_options.upload_bucket = 'public'64 finder_options.upload_results = False65 benchmarkclass = FakeBenchmark66 parser = finder_options.CreateParser()67 benchmark_module.AddCommandLineArgs(parser)68 benchmarkclass.AddCommandLineArgs(parser)69 options, dummy_args = parser.parse_args([])70 benchmark_module.ProcessCommandLineArgs(parser, options)71 benchmarkclass.ProcessCommandLineArgs(parser, options)72 benchmark = benchmarkclass()73 return benchmark, finder_options74 def testPassingPage(self):75 benchmark, finder_options = self.setupBenchmark()76 manager = mock.Mock()77 page = FakePage(benchmark.GetFakeStorySet())78 page.RunNavigateSteps = manager.page.RunNavigateSteps79 page.RunPageInteractions = manager.page.RunPageInteractions80 benchmark.validator.ValidateAndMeasurePage = (81 manager.validator.ValidateAndMeasurePage)82 benchmark.AddFakePage(page)83 self.assertEqual(benchmark.Run(finder_options), 0,84 'Test should run with no errors')85 expected = [mock.call.page.RunNavigateSteps(mock.ANY),86 mock.call.page.RunPageInteractions(mock.ANY),87 mock.call.validator.ValidateAndMeasurePage(88 page, mock.ANY, mock.ANY)]89 self.assertTrue(manager.mock_calls == expected)90 def testFailingPage(self):91 benchmark, finder_options = self.setupBenchmark()92 page = FailingPage(benchmark.GetFakeStorySet())93 benchmark.AddFakePage(page)94 self.assertNotEqual(benchmark.Run(finder_options), 0, 'Test should fail')...

Full Screen

Full Screen

dUtilityBenchmark.test.js

Source:dUtilityBenchmark.test.js Github

copy

Full Screen

...15 this.instance = await dUtilityBenchmark.new({16 from: owner17 });18 });19 describe("#setupBenchmark()", () => {20 it("should revert with length mismatch", async () => {21 await shouldFail.reverting(22 this.instance.setupBenchmark(23 verifier.address,24 [household, household2],25 [ENERGY_DELTA_HASH],26 { from: owner }27 )28 );29 });30 it("should revert when sender is not owner", async () => {31 await shouldFail.reverting(32 this.instance.setupBenchmark(33 verifier.address,34 [household],35 [ENERGY_DELTA_HASH],36 { from: other }37 )38 );39 });40 it("should set up contract for benchmark", async () => {41 const { logs: setupLogs } = await this.instance.setupBenchmark(42 verifier.address,43 [household],44 [ENERGY_DELTA_HASH],45 { from: owner }46 );47 await verifier.givenAnyReturnBool(true);48 const { logs: nettingLogs } = await this.instance.checkNetting(49 [household],50 [0, 1],51 [[2, 3], [4, 5]],52 [6, 7],53 ZOKRATES_OUT54 );55 expectEvent.inLogs(nettingLogs, "NettingSuccess");...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pytest-benchmark automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful