Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Int->String formatting method

Reply
Thread Tools

Int->String formatting method

 
 
=?UTF-8?B?QXJuZSBWYWpow7hq?=
Guest
Posts: n/a
 
      09-30-2006
Thomas Weidenfeller wrote:
> Deniz Dogan wrote:
>> I have a question for you Oliver (or anyone else who'd want to answer
>> this question), is your solution faster than mine?

>
> It does not matter. Unless you have evidence that an implementation
> really affects an application's performance in an unacceptable way there
> are more important criteria to judge an algorithm's implementation. E.g.
> maintainability, or robustness regarding change.


Yep.

I would consider the following good enough even though
it is 3 times slower than the proposed code:

private final static DateFormat df = new
SimpleDateFormat("HH:mm:ss,SSS");
public static String formatMillis3(int millis) {
return df.format(new Date(millis -
TimeZone.getDefault().getOffset(millis)));
}

Arne
 
Reply With Quote
 
 
 
 
=?UTF-8?B?QXJuZSBWYWpow7hq?=
Guest
Posts: n/a
 
      09-30-2006
Wibble wrote:
> That said, Oliver's use of StringBuffer instead of + will
> make his code much faster.


No it does not.

When I test the String code and the StringBuffer code
(fixed to properly add leading zeroes), then the String
code as actually fastest.

That may vary based on platform, Java version etc..

But it is not much faster.

There are simply too few appends on too short
strings to really bring up the StringBuffer advantage.

Arne
 
Reply With Quote
 
 
 
 
Deniz Dogan
Guest
Posts: n/a
 
      10-01-2006
Arne Vajh√łj wrote:
> Thomas Weidenfeller wrote:
>> Deniz Dogan wrote:
>>> I have a question for you Oliver (or anyone else who'd want to answer
>>> this question), is your solution faster than mine?

>>
>> It does not matter. Unless you have evidence that an implementation
>> really affects an application's performance in an unacceptable way
>> there are more important criteria to judge an algorithm's
>> implementation. E.g. maintainability, or robustness regarding change.

>
> Yep.
>
> I would consider the following good enough even though
> it is 3 times slower than the proposed code:
>
> private final static DateFormat df = new
> SimpleDateFormat("HH:mm:ss,SSS");
> public static String formatMillis3(int millis) {
> return df.format(new Date(millis -
> TimeZone.getDefault().getOffset(millis)));
> }
>
> Arne


This code was actually what I was looking for in the first place! I
love pretty Java, no matter how slow it is.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
method to intercept string formatting % operations bradallen Python 3 02-05-2010 08:53 PM
method def in method vs method def in block Kyung won Cheon Ruby 0 11-21-2008 08:48 AM
invoke a method by reflection£¨the method's parameters can not be ArrayList? jerry051 ASP .Net 2 08-02-2005 10:35 AM
ASP.NET: BC30289: Statement cannot appear within a method body. End of method assumed. Mike Wilmot ASP .Net 0 12-15-2003 07:49 PM
Need formatting options menu for formatting hard drive Mark T. Computer Support 3 11-24-2003 11:50 PM



Advertisments