LastPipeBender/app/src/main/java/org/schabi/newpipe/player
Redirion d8b80f961a
Improved performance of getTimeString
This pull requests complements pull request  #2178 by reducing general computational time for the method getTimeString.

On my local machine (Desktop PC with Java) my tests with a sample size of 10000 calls to the method with param 86400001 showed a performance improvement of about 50%.

See sample code below to reproduce:

    private static final StringBuilder stringBuilder = new StringBuilder();
    private static final Formatter stringFormatter = new Formatter(stringBuilder, Locale.getDefault());
    
    public static String getTimeString(int milliSeconds) {
        int seconds = (milliSeconds % 60000) / 1000;
        int minutes = (milliSeconds % 3600000) / 60000;
        int hours = (milliSeconds % 86400000) / 3600000;
        int days = (milliSeconds % (86400000 * 7)) / 86400000;

        stringBuilder.setLength(0);
        return days > 0 ? stringFormatter.format("%d:%02d:%02d:%02d", days, hours, minutes, seconds).toString()
                : hours > 0 ? stringFormatter.format("%d:%02d:%02d", hours, minutes, seconds).toString()
                : stringFormatter.format("%02d:%02d", minutes, seconds).toString();
    }
    
    public static String getTimeStringL(int milliSeconds) {
        long seconds = (milliSeconds % 60000L) / 1000L;
        long minutes = (milliSeconds % 3600000L) / 60000L;
        long hours = (milliSeconds % 86400000L) / 3600000L;
        long days = (milliSeconds % (86400000L * 7L)) / 86400000L;

        stringBuilder.setLength(0);
        return days > 0 ? stringFormatter.format("%d:%02d:%02d:%02d", days, hours, minutes, seconds).toString()
                : hours > 0 ? stringFormatter.format("%d:%02d:%02d", hours, minutes, seconds).toString()
                : stringFormatter.format("%02d:%02d", minutes, seconds).toString();
    }
    
	public static void main(String[] args) throws Exception {
		final int SAMPLE_SIZE = 25000;
		long[] results = new long[SAMPLE_SIZE];
		for(int i = 0; i < SAMPLE_SIZE; i++) {
			long now = System.nanoTime();
			getTimeString(86400001);
			results[i] = System.nanoTime() - now;
		}
		long sum = 0;
		for(int i = 0; i < SAMPLE_SIZE; i++) {
			sum += results[i];
		}
		System.out.println("Average execution time: " + (sum/SAMPLE_SIZE));
		results = new long[SAMPLE_SIZE];
		for(int i = 0; i < SAMPLE_SIZE; i++) {
			long now = System.nanoTime();
			getTimeStringL(86400001);
			results[i] = System.nanoTime() - now;
		}
		sum = 0;
		for(int i = 0; i < SAMPLE_SIZE; i++) {
			sum += results[i];
		}
		System.out.println("Average execution time: " + (sum/SAMPLE_SIZE));
2019-03-04 15:45:59 +01:00
..
event -Enabled play queue control panel for popup video player. 2017-10-30 20:58:45 -07:00
helper Improved performance of getTimeString 2019-03-04 15:45:59 +01:00
mediasession code cleanup 2018-09-11 19:14:21 +02:00
mediasource -Updated ExoPlayer to 2.8.0 2018-06-28 11:58:32 -07:00
playback Add Artist and Duration to MediaDescription 2019-01-31 16:47:33 +01:00
playqueue Merge branch 'dev' into auto_queue_logic 2018-12-04 16:22:18 +00:00
resolver merged upstream/dev 2019-02-16 02:06:18 +05:30
AudioServiceLeakFix.java Fix AudioManager memory leak 2019-02-24 10:51:30 +02:00
BackgroundPlayer.java Fix AudioManager memory leak 2019-02-24 10:51:30 +02:00
BackgroundPlayerActivity.java Fix player switching 2018-01-27 02:57:00 -02:00
BasePlayer.java Merge branch 'dev' into master 2018-11-26 18:00:22 +01:00
MainVideoPlayer.java Fix AudioManager memory leak 2019-02-24 10:51:30 +02:00
PlayerServiceBinder.java -Fixed popup player not playing in foreground. 2017-10-30 20:58:46 -07:00
PlayerState.java -Added skip silence toggle to playback speed control. 2018-06-28 11:58:32 -07:00
PopupVideoPlayer.java Fix AudioManager memory leak 2019-02-24 10:51:30 +02:00
PopupVideoPlayerActivity.java -Added player conversion to background and popup players. 2018-01-03 22:53:38 -08:00
ServicePlayerActivity.java Issue 1505: Delete on right swipe 2018-12-01 00:42:56 +05:30
VideoPlayer.java Merge branch 'dev' into store_last_aspect_ratio 2018-09-29 12:45:10 +02:00