using protractor for performance testing - protractor

I am having a terrible time trying to get decent from end timing numbers using Protractor. I have tried using protractor-perf, but the timings from that don't seem to really reflect the reality of the page load time. It says that the "Program" metric is the total time, however I am seeing it report timings much faster that what you actually see when running the test manually.
I have also tried creating my own timer, and that is proving very difficult based on the controlFlow and all the promises.
Has anyone done any performance testing with Protractor? Is there any good guidance to follow when trying to get timings? Has anyone successfully implemented a timer?

You can use your own timers, you just have to insert them into the control flow right before and after the functions you are trying to measure:
var startTime;
browser.controlFlow().execute(function() {
startTime = Date.now();
});
element(by.css('#startThing')).click();
element(by.css('#endThing')).getText();
browser.controlFlow().execute(function() {
var endTime = Date.now();
var elapsed = endTime - startTime;
console.log('clicking the startThing until getText of the endThing = ' + elapsed + 'ms);
});

Related

Flutter compute function takes time to start execute

I am trying to use Flutters compute function to do some real time heavy image processing using a C++ code and dart ffi.
I tried wrapping the call to the heavy function in a compute to avoid messing with the ui thread and I took some time measurements to see what takes the most time to execute.
the code looks like this:
double _work(CheckPhotoData p) {
DateTime s = DateTime.now();
Pointer<Double> rPointer = Pointer.fromAddress(p.rPointerAddress);
Pointer<Double> gPointer = Pointer.fromAddress(p.gPointerAddress);
Pointer<Double> bPointer = Pointer.fromAddress(p.bPointerAddress);
final a = NativeCCode.checkPhoto(rPointer, gPointer, bPointer, p.w, 1);
print("ACTUAL NativeCCode.checkPhoto took: " + DateTime.now().difference(s).inMilliseconds.toString());
return a;
}
class CheckPhotoWrapper {
static Future<double> checkPhotoWrapper(Uint8List photo) async {
final CheckPhotoData deconstructData = _deconstructData(photo);
DateTime s = DateTime.now();
double res = await compute(_work, deconstructData);
print("compute took: " + DateTime.now().difference(s).inMilliseconds.toString());
return res;
}
...
}
After running the code I got this output:
ACTUAL NativeCCode.checkPhoto took: 106
compute took: 514
(this means that compute took 408ms more than the code it runs)
From what I understand from these results, the actual compute method from dart:async is taking much more time then the actual code its executing and causes a big overhead impacting the performance.
Even worse, my app UI is stuck when the processing starts.
Is there a way to reduce the overhead that compute introduces or a different approach this issue that I couldn't figure out?
Thanks for any idea or a solution to my problem.
Note:
I ran the test on debug mode on a physical device.
CheckPhotoData is a simple class containing the parameters to my _work function.
I am using flutter version 2.2.3, Channel stable
The overhead seems to be caused by debug mode. I saw a similar compute delay of several hundred milliseconds in my app (using Flutter 2.10.2), but when running in release mode it's less than 10 milliseconds.

Can I start the dart Stopwatch with an initial value?

I am looking at the docs of Stopwatch and I'm sure that they don't have a method to start the stopwatch with the initial value.
I am developing an app that requires measuring the elapsed time. Therefore, Stopwatch becomes the obvious choice here. However, there is a use case, where the users of the app may accidentally close the app when clearing the background apps.
Since, running headless dart code in the background is kind of vague right now, I believe it is of best interest to keep track of time and the time gap, if there is any when resuming the app after an accidental close. A separate data object like the following could keep track of time and whether the stopwatch is running...
class StopwatchTracker{
final stopwatch;
final lastUpdated;
final isRunning;
final systemTime;
StopwatchTracker({this.stopwatch, this.lastUpdated, this.isRunning, this.systemTime});
}
With this I have an object that has data about the lastUpdated time from the stopwatch.
Compare this to the systemTime, which will be the device's current system time.
Now, we can see if there is a gap between the lastUpdated time and the systemTime. If there is a gap, the stopwatch should "leap" to the time, by "gap" units.
This StopwatchTracker object will only be initialized on app start/resume and every few seconds, it will update the lastUpdated time. I think the logic is there, but, as I mentioned, the Stopwatch class in dart, doesn't have a method to initialize it with a starting value.
I'm wondering whether I could extend the Stopwatch class to house a method to do that. Or a second option will be to update the ellapsedMillis itself or add the gap in mills to the ellapsedMillis and then show the result on the screen.
Will love to hear from you guys on this!
Yes I can! > Well yes, but actually no
I cannot set the starting value of the stopwatch to start/resume at a certain time or even readjust the current running time.
The easiest solution I have found is to extend the class Stopwatch like so:
class StopWatch extends Stopwatch{
int _starterMilliseconds = 0;
StopWatch();
get elapsedDuration{
return Duration(
microseconds:
this.elapsedMicroseconds + (this._starterMilliseconds * 1000)
);
}
get elapsedMillis{
return this.elapsedMilliseconds + this._starterMilliseconds;
}
set milliseconds(int timeInMilliseconds){
this._starterMilliseconds = timeInMilliseconds;
}
}
At present I don't require much more from this code. Just start the stopwatch at some point and then keep it running. And it can be easily extended for other get types of the class Stopwatch.
This is how I plan to use the class
void main() {
var stopwatch = new StopWatch(); //Creates a new StopWatch, not Stopwatch
stopwatch.start(); //start method, not overridden
stopwatch.milliseconds = 10000; //10 seconds have passed
print(stopwatch.elapsedDuration);//returns the recalculated duration
stopwatch.stop();
}
Want to play with the code, or test it out? Click here

How to skip ahead n seconds while playing track using web audio API?

Using Web Audio API, I'm trying to build an mp3 player with a "Skip ahead 15 seconds" feature.
I'm able to load an mp3 using a source buffer, and can get it to start playing. I want to do something like this, though I know currentTime is not a settable property:
context.currentTime += 15
How do you skip forward n seconds once the song is already playing?
Unfortunately there is no single API call to achieve the desired effect but it's doable. Every AudioBufferSourceNode can only be used once which is why we have to create a new one in order to change something.
Let's imagine we have two variables coming from somewhere called audioContext and audioBuffer. In addition we define two more variables to store the initial startTime and the currently running AudioBufferSourceNode.
let audioBufferSourceNode;
let startTime;
The first time we play the audioBuffer we play it directly from the start. The only special thing here is that we keep a reference to the audioBufferSourceNode and that we remember the startTime.
audioBufferSourceNode = audioContext.createBufferSource();
audioBufferSourceNode.buffer = audioBuffer;
audioBufferSourceNode.connect(audioContext.destination);
startTime = context.currentTime;
audioBufferSourceNode.start(startTime);
If you want to skip ahead some time later the previously started audioBufferSourceNode needs to be stopped first.
const currentTime = context.currentTime;
audioBufferSourceNode.stop(currentTime);
audioBufferSourceNode.disconnect();
In addition a new one needs to be created by reusing the same audioBuffer as before. The only difference here is that we apply an offset to make sure it skips 15 seconds ahead.
audioBufferSourceNode = audioContext.createBufferSource();
audioBufferSourceNode.buffer = audioBuffer;
audioBufferSourceNode.connect(audioContext.destination);
audioBufferSourceNode.start(currentTime, currentTime - startTime + 15);
To be prepared to skip another time it's necessary to update the startTime.
startTime -= 15;
This is of course an oversimplified example. In reality there should be a check to make sure that there is enough audio data left to skip ahead. You could also apply a little fade-in/out when skipping to avoid click sounds. ... This is only meant to illustrate the general idea.

not accurate setTimeout and it works only on mousedown

I have problem with setTimeout.
In all major browsers it works fine but not in IE...
I'm creating a facebook app- puzzle. When player press Start button, the timer starts count his time of playing one game.
At the beginning I used setInterval to increase timer but with cooperate of facebook scripts it delayed about 2 seconds at the end of game. Then I found on stackoverflow trick to increase accuracy of timer: setInterval timing slowly drifts away from staying accurate
And again- without facebook it worked fine, no delays were shown. With facebook it still has delays.
Now to condensate info that might interest You:
When user clicks Start then I create new Date as startTime.
When user ends game script creates finalTime new Date, then substract finalTime - startTime.
In code there is setTimeout:
(...)
f : function() {
var sec_time = Math.floor((puzzle.nextAt - puzzle.startTime)/1000);
$('.timer').html(sec_time);
if (!puzzle.startTime) {
puzzle.startTime = new Date().getTime();
puzzle.nextAt = puzzle.startTime;
$('.timer').html('0');
}
puzzle.nextAt += 100;
puzzle.to = setTimeout(puzzle.f, puzzle.nextAt - new Date().getTime());
}
(...)
when user place on correct place last puzzle piece then I call clearTimeout(puzzle.to);
I have now 2 issues:
not accurate time, in IE it can be even 7 second difference!
in IE during game it works only when user have mousedown... :/
To drag puzzles I use jQuery drag & drop plugin.
At least very helpful info will be how to achieve accurate timer.
You should put your scripts in jQuery's ready function and not at the bottom of the page, as the Facebook SDK is loaded asynchronously and may impact timed executions if they're initiated at the bottom of the page.
As for timing, you're gonna see inaccuracy of between 15ms and 45ms in IE7 depending on other JS executions on the page. Your 100ms timeout will drift badly because of this. Better to record a start time and build a timer with a higher polling frequency than needed and do a comparison between start time and 'now' in each cycle to determine what to do next.

swfupload get timer left

is it any possible to get time left for uploading files using swfupload?
You can most certainly estimate the time remaining, but this isn't a feature built-in to SWFUpload to my knowledge. Here's what I do:
In your uploadStart() handler for your file, record the start time of the upload and store in somewhere.
var startTime = +new Date(); // the current date time in UTC * 1000 milliseconds
Then, in your uploadProgress() handler for the same file:
var percentage = bytesLoaded/file.size,
timeDiff = +new Date() - startTime,
status = (percentage > 0 ? Math.round(timeDiff / percentage / 1000 * (1 - percentage)) + " seconds remaining." : "Uploading...");
Works well!
I hope this is helpful.
EDIT, added test for percentage > 0
No, because the time taken to upload anything over a normal Internet connection can never be known in advance due to speed fluctuations. On the other hand swfupload provides a progress handler to report the percentage uploaded so you can either use that to display a progress counter/bar or guesstimate the time remaining based on the time already spent and hope it's somewhat accurate.