473,395 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

String functions vs. XML literals... speed

I was wondering, ... does anyone know off hand which is faster?

I've seen articles where people suggest the method of using XML literals to
build strings... something like:

Dim s As String = <s>This is some string, built on <%= Format(Now,
"MM/dd/yyyy HH:mm") %></s>.Value

and I'm just curious how this might compare in speed to using String.Format,
more like:

Dim s As String = String.Format("This is some string, built on {0}",
Format(Now, "MM/dd/yyyy HH:mm"))

Jul 8 '08 #1
1 1135
Arthur Dent wrote:
I was wondering, ... does anyone know off hand which is faster?

I've seen articles where people suggest the method of using XML literals
to build strings... something like:

Dim s As String = <s>This is some string, built on <%= Format(Now,
"MM/dd/yyyy HH:mm") %></s>.Value
I'm not sure if an xml literal will end up as a string or as an object
tree, but either way you are adding another layer that the code has to
work through to get to the result.
and I'm just curious how this might compare in speed to using
String.Format, more like:

Dim s As String = String.Format("This is some string, built on {0}",
Format(Now, "MM/dd/yyyy HH:mm"))
I don't see why you are using the Format function in a call to
String.Format. Use the String.Format method as it was intended:

Dim s As String = String.Format("This is some string, built on
{0:MM/dd/yyyy HH:mm}", Now)

If you only have a single value to format, you can do the same with an
overload of the ToString method:

Dim s As String = Now.ToString("'This is some string, built on
'MM/dd/yyyy HH:mm")

I believe the last one is the most efficient way to format a date into a
string.

--
Göran Andersson
_____
http://www.guffa.com
Jul 8 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Kevin Buffardi | last post by:
To those experts in standard C/C++... In past I've been quick to use the string.h library for convenience, but now I'm working on a project where I'm trying to maximize portability so I want to...
17
by: Olivier Bellemare | last post by:
I've tried to make a function that returns the middle of a string. For example: strmid("this is a text",6,4); would return "is a". Here is my code: char *strmid(char *texte, int depart,...
6
by: kobu.selva | last post by:
I was recently part of a little debate on the issue of whether constants and string literals are considered "data objects" in C. I'm more confused now than before. I was always under the...
19
by: Ross A. Finlayson | last post by:
Hi, I hope you can help me understand the varargs facility. Say I am programming in ISO C including stdarg.h and I declare a function as so: void log_printf(const char* logfilename, const...
52
by: junky_fellow | last post by:
char *str1 = "Hello"; char arr1 = { "Hello" }; char arr2 = { 'H', 'e', 'l', 'l', 'o' }; Is it legal to modify str1, arr1 and arr2 ?
6
by: copx | last post by:
Can you / are you supposed to free() string literals which are no longer needed? In my case I've menu construction code that looks like this: menu_items = list_new(); list_add(menu_items,...
8
by: Brand Bogard | last post by:
Does the C standard include a library function to convert an 8 bit character string to a 16 bit character string?
33
by: Michael B Allen | last post by:
Hello, Early on I decided that all text (what most people call "strings" ) in my code would be unsigned char *. The reasoning is that the elements of these arrays are decidedly not signed. In...
4
by: =?ISO-8859-15?Q?Jean=2DFran=E7ois?= Lemaire | last post by:
Hello all, I'm learning C and I still am struggling to understand some basic concepts. For example, I read in the standard that with functions such as strcpy, 'If copying takes place between...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.