Alek Posted October 21, 2014 Share Posted October 21, 2014 I think we're all here to learn. I can count all the true java wizards I know in the botting community on one hand. 1 Link to comment Share on other sites More sharing options...
Fay Posted October 21, 2014 Share Posted October 21, 2014 (edited) This is the same thing as above but even worse. I really don't see why people insist on making their code unreadable just because "it saves lines". I know the ternary is actually slower in C# when compared to nested if statements because of the JIT trying to make optimizations, not sure about Java. Apaec is faster on average by 90ms on my computer. Apaec vs. Czar 69.194 159.609 Baseline code: package dateBaseLiner; public class IWannaBeLikeKanye { public static void main(String[] args) { for (int f = 0; f < 1000; f++) { long startTime = System.currentTimeMillis(); for (int a = 0; a < 1000; a++) { for (int y = 0; y < 1000; y++) { format(startTime); } } long endTime = System.currentTimeMillis(); System.out.println((endTime - startTime)); } } public static String format(final long time) { final int sec = (int) (time / 1000), h = sec / 3600, m = sec / 60 % 60, s = sec % 60; return (h < 10 ? "0" + h : h) + ":" + (m < 10 ? "0" + m : m) + ":" + (s < 10 ? "0" + s : s); } public static String tformat(long time) { StringBuilder t = new StringBuilder(); long total_secs = time / 1000L; long total_mins = total_secs / 60L; long total_hrs = total_mins / 60L; int secs = (int) total_secs % 60; int mins = (int) total_mins % 60; int hrs = (int) total_hrs % 24; if (hrs < 10) { t.append("0"); } t.append(hrs).append(":"); if (mins < 10) { t.append("0"); } t.append(mins).append(":"); if (secs < 10) { t.append("0"); } t.append(secs); return t.toString(); } } Edited October 21, 2014 by Fay Link to comment Share on other sites More sharing options...
NotoriousPP Posted October 21, 2014 Share Posted October 21, 2014 That awkward moment when SimpleDateFormat isn't simple enough for anyone to understand.... public String getSuperComplexFormatTime (long time) { return new SimpleDateFormat("H:mm:ss").format(new Date(time - TimeZone.getDefault().getRawOffset())); } Link to comment Share on other sites More sharing options...