I have a slight bottleneck in my code, the simplicity of which leads me to
believe it is either insurmountable, or easily speeded up. I have an
ArrayList of numbers (integers, which are in fact database primary keys).
In order to pass all of these keys into a stored procedure, I generate one
long space delimited string by concatenating the IDs and pass it into SQL
Server as an NTEXT field (the stored procedure then breaks the NTEXT field
into a table and does a join with another but thats by the way). When I
have, say, 16,000 primary keys in my list, the section below can take quite
a long time (seconds!). Is this reasonable? If not, can I speed it up any?
I'm guessing the compiler is quite smart at optimization and that something
as simple as this is already more or less maxed out.
My ideas are: perhaps iterating the collection with "For Each" might be
slower than directly indexing the array. Also, perhaps I should generate a
string of the correct length and then modify it rather than relying on the
runtime to resize or re-create the string on each iteration (but strings are
immutable, right?). Perhaps there is a different way I can convert an
integer to a string that is more efficient than "ToString".
An ideas?
(theNodeIDs is an ArrayList, theNodeIDsStrin g is a string)....
For Each theNodeID As Integer In theNodeIDs
theNodeIDsStrin g += theNodeID.ToStr ing + " "
Next
Thanks,
Robin 6 1276
One way to optimize, would be to use a stringbuilder for the concatenation.
You should see a significant improvement.
"Robin Tucker" <id************ *************@r eallyidont.com> wrote in
message news:cv******** ***********@new s.demon.co.uk.. . I have a slight bottleneck in my code, the simplicity of which leads me to believe it is either insurmountable, or easily speeded up. I have an ArrayList of numbers (integers, which are in fact database primary keys). In order to pass all of these keys into a stored procedure, I generate one long space delimited string by concatenating the IDs and pass it into SQL Server as an NTEXT field (the stored procedure then breaks the NTEXT field into a table and does a join with another but thats by the way). When I have, say, 16,000 primary keys in my list, the section below can take quite a long time (seconds!). Is this reasonable? If not, can I speed it up any? I'm guessing the compiler is quite smart at optimization and that something as simple as this is already more or less maxed out.
My ideas are: perhaps iterating the collection with "For Each" might be slower than directly indexing the array. Also, perhaps I should generate a string of the correct length and then modify it rather than relying on the runtime to resize or re-create the string on each iteration (but strings are immutable, right?). Perhaps there is a different way I can convert an integer to a string that is more efficient than "ToString".
An ideas? (theNodeIDs is an ArrayList, theNodeIDsStrin g is a string)....
For Each theNodeID As Integer In theNodeIDs theNodeIDsStrin g += theNodeID.ToStr ing + " " Next
Thanks,
Robin
One way to optimize, would be to use a stringbuilder for the concatenation.
You should see a significant improvement.
"Robin Tucker" <id************ *************@r eallyidont.com> wrote in
message news:cv******** ***********@new s.demon.co.uk.. . I have a slight bottleneck in my code, the simplicity of which leads me to believe it is either insurmountable, or easily speeded up. I have an ArrayList of numbers (integers, which are in fact database primary keys). In order to pass all of these keys into a stored procedure, I generate one long space delimited string by concatenating the IDs and pass it into SQL Server as an NTEXT field (the stored procedure then breaks the NTEXT field into a table and does a join with another but thats by the way). When I have, say, 16,000 primary keys in my list, the section below can take quite a long time (seconds!). Is this reasonable? If not, can I speed it up any? I'm guessing the compiler is quite smart at optimization and that something as simple as this is already more or less maxed out.
My ideas are: perhaps iterating the collection with "For Each" might be slower than directly indexing the array. Also, perhaps I should generate a string of the correct length and then modify it rather than relying on the runtime to resize or re-create the string on each iteration (but strings are immutable, right?). Perhaps there is a different way I can convert an integer to a string that is more efficient than "ToString".
An ideas? (theNodeIDs is an ArrayList, theNodeIDsStrin g is a string)....
For Each theNodeID As Integer In theNodeIDs theNodeIDsStrin g += theNodeID.ToStr ing + " " Next
Thanks,
Robin
Robin,
"Robin Tucker" <id************ *************@r eallyidont.com> schrieb: I have a slight bottleneck in my code, the simplicity of which leads me to believe it is either insurmountable, or easily speeded up. I have an ArrayList of numbers (integers, which are in fact database primary keys). In order to pass all of these keys into a stored procedure, I generate one long space delimited string by concatenating the IDs and pass it into SQL Server as an NTEXT field (the stored procedure then breaks the NTEXT field into a table and does a join with another but thats by the way). When I have, say, 16,000 primary keys in my list, the section below can take quite a long time (seconds!). Is this reasonable? If not, can I speed it up any? I'm guessing the compiler is quite smart at optimization and that something as simple as this is already more or less maxed out.
My ideas are: perhaps iterating the collection with "For Each" might be slower than directly indexing the array.
The difference is marginal.
Also, perhaps I should generate a string of the correct length and then modify it rather than relying on the runtime to resize or re-create the string on each iteration (but strings are immutable, right?).
That's the bottleneck. Strings are immutable and your code will create new
string objects several times. Instead of using a string, use a
'StringBuilder' instead:
For Each theNodeID As Integer In theNodeIDs theNodeIDsStrin g += theNodeID.ToStr ing + " " Next
\\\
Dim sb As New StringBuilder()
For Each NodeID As Integer In NodeIDs
sb.Append(NodeI D.ToString())
sb.Append(" ")
Next NodeID
.... = sb.ToString()
///
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Robin,
"Robin Tucker" <id************ *************@r eallyidont.com> schrieb: I have a slight bottleneck in my code, the simplicity of which leads me to believe it is either insurmountable, or easily speeded up. I have an ArrayList of numbers (integers, which are in fact database primary keys). In order to pass all of these keys into a stored procedure, I generate one long space delimited string by concatenating the IDs and pass it into SQL Server as an NTEXT field (the stored procedure then breaks the NTEXT field into a table and does a join with another but thats by the way). When I have, say, 16,000 primary keys in my list, the section below can take quite a long time (seconds!). Is this reasonable? If not, can I speed it up any? I'm guessing the compiler is quite smart at optimization and that something as simple as this is already more or less maxed out.
My ideas are: perhaps iterating the collection with "For Each" might be slower than directly indexing the array.
The difference is marginal.
Also, perhaps I should generate a string of the correct length and then modify it rather than relying on the runtime to resize or re-create the string on each iteration (but strings are immutable, right?).
That's the bottleneck. Strings are immutable and your code will create new
string objects several times. Instead of using a string, use a
'StringBuilder' instead:
For Each theNodeID As Integer In theNodeIDs theNodeIDsStrin g += theNodeID.ToStr ing + " " Next
\\\
Dim sb As New StringBuilder()
For Each NodeID As Integer In NodeIDs
sb.Append(NodeI D.ToString())
sb.Append(" ")
Next NodeID
.... = sb.ToString()
///
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Thanks both for the above. The operation was taking ~15 seconds but is now
to all intents and purposes instantaneous :))
Robin
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. .. Robin,
"Robin Tucker" <id************ *************@r eallyidont.com> schrieb: I have a slight bottleneck in my code, the simplicity of which leads me to believe it is either insurmountable, or easily speeded up. I have an ArrayList of numbers (integers, which are in fact database primary keys). In order to pass all of these keys into a stored procedure, I generate one long space delimited string by concatenating the IDs and pass it into SQL Server as an NTEXT field (the stored procedure then breaks the NTEXT field into a table and does a join with another but thats by the way). When I have, say, 16,000 primary keys in my list, the section below can take quite a long time (seconds!). Is this reasonable? If not, can I speed it up any? I'm guessing the compiler is quite smart at optimization and that something as simple as this is already more or less maxed out.
My ideas are: perhaps iterating the collection with "For Each" might be slower than directly indexing the array.
The difference is marginal.
Also, perhaps I should generate a string of the correct length and then modify it rather than relying on the runtime to resize or re-create the string on each iteration (but strings are immutable, right?).
That's the bottleneck. Strings are immutable and your code will create new string objects several times. Instead of using a string, use a 'StringBuilder' instead:
For Each theNodeID As Integer In theNodeIDs theNodeIDsStrin g += theNodeID.ToStr ing + " " Next
\\\ Dim sb As New StringBuilder() For Each NodeID As Integer In NodeIDs sb.Append(NodeI D.ToString()) sb.Append(" ") Next NodeID ... = sb.ToString() ///
-- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Thanks both for the above. The operation was taking ~15 seconds but is now
to all intents and purposes instantaneous :))
Robin
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. .. Robin,
"Robin Tucker" <id************ *************@r eallyidont.com> schrieb: I have a slight bottleneck in my code, the simplicity of which leads me to believe it is either insurmountable, or easily speeded up. I have an ArrayList of numbers (integers, which are in fact database primary keys). In order to pass all of these keys into a stored procedure, I generate one long space delimited string by concatenating the IDs and pass it into SQL Server as an NTEXT field (the stored procedure then breaks the NTEXT field into a table and does a join with another but thats by the way). When I have, say, 16,000 primary keys in my list, the section below can take quite a long time (seconds!). Is this reasonable? If not, can I speed it up any? I'm guessing the compiler is quite smart at optimization and that something as simple as this is already more or less maxed out.
My ideas are: perhaps iterating the collection with "For Each" might be slower than directly indexing the array.
The difference is marginal.
Also, perhaps I should generate a string of the correct length and then modify it rather than relying on the runtime to resize or re-create the string on each iteration (but strings are immutable, right?).
That's the bottleneck. Strings are immutable and your code will create new string objects several times. Instead of using a string, use a 'StringBuilder' instead:
For Each theNodeID As Integer In theNodeIDs theNodeIDsStrin g += theNodeID.ToStr ing + " " Next
\\\ Dim sb As New StringBuilder() For Each NodeID As Integer In NodeIDs sb.Append(NodeI D.ToString()) sb.Append(" ") Next NodeID ... = sb.ToString() ///
-- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://dotnet.mvps.org/dotnet/faqs/> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Kyle |
last post by:
Hello all!
I'm looking into developing a biological program for modeling and
sequencing DNA and other biological processes. The program's main
focus would be to look for similarities and differences between
different models of experiments. I would also being using information
from this website in my work also:
http://www.ncbi.nlm.nih.gov/
|
by: Andreas Falck |
last post by:
Hi,
I ran the code below on two different versions, 4.0.14 and 4.0.16
respectively, both running RH 7.3 on intel.
In version mysql server version 4.0.14 the SELECT privelege suffices
for "optimize table", but (seemingly) the server version 4.0.16
requires INSERT as well.
Is the INSERT privelege necessary for performing optimize in mysql
|
by: Silly |
last post by:
byte Name = new byte;
uint len = (uint)Name.Length;
uint err = MyFunction(devID, out Name, out len);
When this code is run in release build with optimize code set to true, len
is evaluated to 0. If it is run with optimize code set to false, len is
evaluated as 256 (what i want).
If I add an extra line of code after declaring len, like:
|
by: Reddy |
last post by:
The sql query for my datagrid returns 100, 000 records. But the datagrid
should display 20 records per page. I am using datagrid paging, but it is
taking too much time for the page to load. Is there any way I can optimize
the speed. Any sample code would be great.
Thanks,
Reddy
|
by: Arne Demmers |
last post by:
Hi,
As a project of mine I have to do some C programming, which in fact isn't
the real problem. The problem it self is that I will have to write some code
that is as minimal as possible, and as fast as possible.
Are there any gidelines for this kind of thing? How do I know if my code is
possibly the smallest and fastest I could write for a certain algo?? And
where can I find thise kind of guidelines???
| |
by: Steeve |
last post by:
Hi,
Is this possible to optimize this method ? It's the method than I call
most offen in my application (result of Sampling Profiling in Visual
Studio Performance report)
I use this method to find a particular Node in a List<Node>.
(Note: JobNumber is a int)
public bool NodeMachineJobPredicate(Node N)
|
by: kenneth |
last post by:
I was trying to use multiple thread to optimize my following code, but
met some problems, anyone can help me?
k are initialized.
int computePot() {
int i, j;
for( i=0; i<500; i++ ) {
for( j=0; j<i-1; j++ ) {
|
by: jwrweatherley |
last post by:
I'm pretty new to python, but am very happy with it. As well as using
it at work I've been using it to solve various puzzles on the Project
Euler site - http://projecteuler.net. So far it has not let me down,
but it has proved surprisingly slow on one puzzle.
The puzzle is: p is the perimeter of a right angle triangle with
integral length sides, {a,b,c}. which value of p < 1000, is the
number of solutions {a,b,c} maximised?
Here's my...
|
by: pavanip |
last post by:
Hi,
I have an application like Optimize System Performance by using Memory speed, cpu speed and Disk speed.
How to optimize memory speed,disk optimization and CPU optimization.
Please provide me some sample source code to optimize system performance.
Thanks
pavani
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |