Tracking function execution time with jasmine

alecxe

Is it possible to create a reusable jasmine matcher that would assert a function to run for less than N seconds?

Sample expectation style:

expect(someFunction, [arg1, arg2]).toBeCompletedForLessThan(3);
expect(obj.someMethod, [arg1, arg2]).toBeCompletedForLessThan(5);

We'd like to tie this up with Protractor and custom performance tests where we want to assert that certain UI execution steps don't go beyond the time limit.

Florent B.

I would measure the elapsed time with a custom timer and then assert the result with .toBeLessThan:

var timer = Timer();

$("#mytext").getText().then(function(text){
    console.log(text);
});

expect(timer.elapsed).toBeLessThan(1000);   // to be under 1 second

The timer:

var Timer = function() {
  var starttime = 0;

  browser.controlFlow().execute(function() {
    starttime = Date.now()
  });

  return {
    get elapsed() {
      return browser.controlFlow().execute(() => Date.now() - starttime);
    }
  };
};

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Why is the execution time of this function call changing?

How to limit execution time of a function call in Python

Measuring execution time of a function in C++

Tracking the script execution time in PHP

Why spyOn "stops all execution of a function" in Jasmine (asking for clarification on Jasmine 2.2 Documentation on Spies)

Java - Repeated function call reduces execution time

How to calculate the execution time of an async function in JavaScript?

Haskell - Is there a way to limit the execution time for a given function?

How to obtain the execution time of a function in Julia?

How to measure the execution time of an asynchronous function in nodejs?

Measure the execution time of a function

PHP function execution time taking long

Best Method for Measuring Execution Time of a Function

Function execution time

Profiling of function with small execution time using %prun

How to approximate execution time of ArangoDB count function

Swift - function wise time consumption tracking

jasmine spyOn calls the real function after the first test execution

GC Function Pricing by CPU Time or Execution Time?

Return for function after certain execution time

Function for calculation execution time of other functions

Question 1: execution time of calling the function

Decorator to Find the Time of Execution of a Function in Python

Is there a way to list all nodejs function execution time?

Is the cold start time related to function execution time in Serveless Computing?

JavaScript function execution time

Python - measure function execution time with decorator

Execution of function on first time open only

Why is execution time of this function increasing?