For GWT client code, the general rule is that the synchronized keyword
is ignored because it's single threaded. In the case of StringBuffer and
StringBuilder, they are both emulated and the source code for their
client-side versions is identical apart from the name. So for GWT, it
makes no difference which you use.
StringBuilder was only introduced in Java 1.5, so there's a lot of older
code and examples that use StringBuffer that could/should use
StringBuilder.
Paul
- Manolo
> --
> You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
> To post to this group, send email to google-we...@googlegroups.com.
> To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
>
>
/Andreas
-Manolo
but if I understood you correctly you said there was a client side
performance penalty. If it's only in compile time I think it's easier
to let devs use stringbuilder in JS mode as well to be consistent.
/Andreas
On Tue, Jul 13, 2010 at 10:59 AM, Manuel Carrasco Moñino
-Manolo
I have coded a simple test (see below) to check append and these are
my results (Compiled code):
- all browsers except IE performs identical using String, StringB.
- IE6 performs better using StringB.
- IE8 performs better using normal String.
In hosted mode, the performance is better for StringB
Cheers
-Manolo
public void testStringOperations() {
int TIME = 20000;
String DATA = "sadfasdf";
String s = "";
double ss = new Date().getTime();
for (int i=0; i<TIME; i++) {
s += DATA;
}
double se = new Date().getTime();
String a = "";
double as = new Date().getTime();
for (int i=0; i<TIME; i++) {
a = a + DATA;
}
double ae = new Date().getTime();
double bs = new Date().getTime();
StringBuffer b = new StringBuffer();
for (int i=0; i<TIME; i++) {
b.append(DATA);
}
double be = new Date().getTime();
double us = new Date().getTime();
StringBuilder u = new StringBuilder();
for (int i=0; i<TIME; i++) {
u.append(DATA);
}
double ue = new Date().getTime();
RootPanel.get().add(new Label(se - ss + " " + s.length() + " String += "));
RootPanel.get().add(new Label(ae - as + " " + a.length() + "
String = String + "));
RootPanel.get().add(new Label(be - bs + " " + b.length() + "
StringBuffer" ));
RootPanel.get().add(new Label(ue - us + " " + u.length() + "
StringBuilder" ));
}