Click here to Skip to main content
15,891,721 members
Everything / General Programming / Optimization

Optimization

optimization

Great Reads

by Sandeep Mewara
An optimization programming technique
by Ryan Scott White
A fast, possibly the fastest, square root function for Big Integers and Floats in C# and Java.
by Mahmud Hasan
How to use variable in SELECT TOP SQL command
by D Sarthi Maheshwari
Discussing about streams... about streaming... about functional streaming... and nothing else

Latest Articles

by Michael Sydney Balloni
A "new" queue data structure is described and compared with existing collection types
by Ryan Scott White
A fast, possibly the fastest, square root function for Big Integers and Floats in C# and Java.
by Jian_Zhang
Democratizing AI with Intel-Optimized Software
by Michael Sydney Balloni
See how Rust stacks up against C-ish, C++, and C#

All Articles

Sort by Title

Optimization 

15 Jan 2017 by Member 12951338
I do not know what is causing this problem. I have 2 forms (Search form & Accounts form) in Accounts Form there is a Search button which opens the Search. Code for opening the search form:private void btnSearch_Click(object sender, EventArgs e) { SearchForm sf = new...
15 Jan 2017 by Dave Kreskowiak
Googling this isn't going to give you any answers. You MUST use the debugger on this code and find the variable that is null when the exception is thrown. Then go backwards through the code and find out why the variable contains null.We can't do this for you. We can't run the code and we...
15 Jan 2017 by Wendelius
As far as I can see, when you create the SearchForm, you call the default constructor, not the one with account form defined as parameter. Later in the code you try to use the variable rf, which is null because you used the wrong constructor.If the btnSearch is located on the account form,...
14 Oct 2019 by dhaskins
I have a form with 7 buttons and 7 comboboxes. When I click one of the buttons, I want to put text into the corresponding combobox, so button number 4 puts text into combobox4. Simple enough, however, I do not want to have to repeat my code, I want it all in one block, so one chunk handles...
14 Oct 2019 by OriginalGriff
Each control has a Tag property, which is available for you to use for whatever purpose you want. If your form constructor sets the Tag of each button to the appropriate combobox, you juts have to cast the value to a ComboBox and use it: button4.Tag = ComboBox4; ... ComboBox cb = button.Tag as...
17 Dec 2021 by Michael Haephrati, rolsaad
We were asked to develop a piece of software which will select an optimal combination of sentences from e-books which will give the closest result to a set of targets for each character.
23 Jul 2019 by andrew898701
Hello, I am writing code to process part numbers from a digital scanner. The digital scanner reads part numbers on a label and if the part is listed in the "datagridview" display of the program then it stores them as "scanned" (not shown here) but if they are not found then it returns an...
23 Jul 2019 by Patrice T
Quote: Advice on minimizing nested loops? The question starts bad because there is no nested loops in this code! Fix: ... goto Fix; Generally speaking, using labels and gotos in code is a bad idea because it makes the code confuse (spaghetti code) and difficult to debug...
23 Jul 2019 by BillWoodruff
I could fracture my brain in trying to figure out what this complex code is doing :) A few things jump out at me on quick inspection: 1 you call trim on the input more than once 2 in the loop through the DGV rows, you may call 'ScanFix which appears to do another loop through the rows ? 3...
13 Feb 2017 by SanalSundar
I have lot of entities which contain thousands of records, with diverse values like some have ranges using BETWEEN numbers,some with IN variable having multiple values in it, some with LIKE variable containing multiple values of different data types such as integer, string & decimal. For example...
13 Feb 2017 by Patrice T
Quote:Please do suggest which algorithm will fit the bill to correctly identify a given record(s) based on the set of values provided.You are in the worst possible situation, the flat text data imply the use of brut force. The name of fields in every records make it even worse the CSV...
22 Jun 2022 by Stephane Capo
C++ optimization for map using string key among others
28 Nov 2014 by Member 8779903
1) Prove by hand calculation that artificial ants using only forward (oronly backward) pheromone update do not converge toward the common use of theminimum cost path in the double bridge experiment.2) Prove by hand calculation that, if artificial ants are given the capability(through...
28 Nov 2014 by OriginalGriff
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.Try it yourself, you may find it...
8 Mar 2013 by Nayab Rahil
Can any please post Ant Colony Optimization code in details. along with its detail like how the algorithm works and when and where we should use Ant Colony Optimization technique. Code is really important?
8 Mar 2013 by Sergey Alexandrovich Kryukov
Please see my comment to the question. You cannot expect than anyone will write code for you. Start from here:http://en.wikipedia.org/wiki/Ant_colony_optimization_algorithms[^].—SA
20 Dec 2014 by Pravin baskaran
A python implementation of an ant colony optimization algorithm with offline pheromone update to solve ry48p, an asymmetric travelling sales man problem
18 Jan 2018 by OriginalGriff
It doesn't quite work like that. We do not do your work for you. If you want someone to write your code, you have to pay - I suggest you go to Freelancer.com and ask there. But be aware: you get what you pay for. Pay peanuts, get monkeys. The idea of "development" is as the word suggests: "The...
19 Jan 2018 by suraty
Hello, I am a beginner in Cloud and Cloudsim. In a paper steps for implementing ABC-SA (implementing a hybrid optimization algorithm by integrating the functionality of simulated annealing (SA) into artificial bee colony (ABC) algorithm) algorithm are as below: (1) Initializing the population...
16 Nov 2011 by I.explore.code
Hi folks,I have a potentially silly sounding question considering the fact that there are several conventional ways of doing it, but I was wondering if anyone knows of a fast way of computing the ASCII value of a whole string of characters. Possibly using some sort of bit-filddling hacks....
2 Feb 2015 by vivek.khatri
I have almost every piece of code, I just need it to be optimized using correct IF_ELSE conditions and arranging the right flow.I have a webform (UserProfile.aspx), which contains FormView (to display user profile).In FormView ItemTemplate, I have put simple HTML and ASP.Net Labels to...
2 Feb 2015 by EasyHero
To verify a logged in user, use session and check if the label where the session variable is stored is empty.didn't really get your question, are you trying to open some controls if a user is logged in? if yes, why not set the controls to be open, then ensure the user is logged in before its...
1 Feb 2019 by Kohila G
So, yesterday my teacher gave us a question to try. The link for the question is Rearrange an array such that arr[i] = i - GeeksforGeeks[^] He just told the problem and the input and told us to try. I came up with a solution and showed it to him. But, he said that my code is bad and not...
1 Feb 2019 by KarstenK
I see three reasons 1.you check for a[i] == -1 so in the else you neednt a check against it. 2. you have 2 n-loops 3. you need one assignment less. x=a[i]; a[i]=a[x];//direct without buffering a[x] = x;
16 May 2013 by bugistar
I am using Tuning Adviser to suggest indexes. I am not sure should I make all suggested indexes (many are non-clustered). I am afraid that I will do the opposite (degradation) by using so many indexes. Any suggestions ?
16 May 2013 by _Damian S_
By definition there can only be one clustered index per table, as that defines the physical order of records. You generally don't want to define a clustered index on a field that doesn't constantly increase (like an autonumber field), as any insert into the middle of the values would result in...
19 May 2013 by willMJ
Before creating indexes to optimize your database you need to be sure how to use indexes. You need to locate frequently used queries and then you can start creating indexes ...Please read this - SQL Server Performance Tips and Guidelines[^]
28 Feb 2020 by nagpalh
Hi Guys, I recently had a coding test for a position of algorithm engineer in a company. They gave me the following problem. Although, I failed the coding challenge, but I would like to know the solution to the problem to see where did I go...
10 Feb 2020 by OriginalGriff
Quote: I'd really appreciate if anyone could give a solution to it. We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for...
10 Feb 2020 by Patrice T
Quote: but I would like to know the solution to the problem There is about 1 solution per programmer Quote: where did I go wrong? As programmer, your job is also to make sure that your code give correct solution. To do so, you have to build...
10 Apr 2020 by Member 14798076
Well, there is a guy who is asking everybody to do this test because he is (supposedly) hiring people for his team. But when I did this test I never got an answer and the guy just disappeared silently. I think he has no money, and just...
19 Dec 2014 by OKarpov
How to use ASM in C#.NET and most fast memory copy method
8 Nov 2017 by dinesh_redhawk
Hello friends,I have written the folowing code to populate the data from a object in a tablelayoutpanel control. It works :), but when its loading the data onto the table, it flickers/jumps for few seconds and then after 2-3 seconds when its done processing the data it populates the data :(...
8 Jun 2015 by Staffan Bruun
Try putting the code that generates the new controls between a SuspendLayout/ResumeLayout pair:private void button1_Click(object sender, EventArgs e){ SuspendLayout(); // code that recreates controls on the form ResumeLayout();}This will keep the window from...
21 Apr 2020 by Demuter
Faced a problem. I need to poll the device by serial port using the Modbus protocol. But polling the device takes a long time - about 2 seconds. True, my program still additionally constantly polls devices in a separate thread, but I wanted it...
21 Apr 2020 by OriginalGriff
Start by finding out where it's spending it#s time: pepper it with Stopwatch Class (System.Diagnostics) | Microsoft Docs[^] instances and log the various parts of the operation to a file at the end. Then focus on the longest part, and add more...
21 Apr 2020 by User 11060979
After all discussions I would try something like below in your receiver code section to speed up communication. I hope it helps and that I did not make to much mistakes. // The following expects that serialPort.ReadTimeout is setup // for...
27 May 2020 by Demuter
I tried to poll the device using the Modbus protocol for TCP/IP, and it works well, but there are problems. If I run this code on a weak computer, the response time will increase and very much... The difference in polling speed is about 6...
27 May 2020 by Gerry Schmitz
You keep opening a new connection every time you make a request; that's where all your "lag" is. You create a connection to a device, and keep it open while you are "sending and receiving." You close the connection when you're "done".
17 Apr 2013 by Bartlomiej Filipek
Experiments about compilation times and file structure in C++, using GCC, MinGW, Visual Studio.
14 Jul 2020 by Pranshu Kashyap
Link to The Problem: https://codeforces.com/problemset/problem/166/E[^] Problem Statement: *You are given a tetrahedron. Let's mark its vertices with letters A, B, C, and D correspondingly. An ant is standing in the vertex D of the...
14 Jul 2020 by OriginalGriff
We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! The idea of these challenges is to test your knowledge; your abilities. To give you a chance to change the way you think about...
14 Jul 2020 by Patrice T
Quote: I didn't knew that this site is to tell you that if you are stuck at any problem then tell your doubts to your mentor and they will simply say solve yourself we are here just for posting nonsense answers. In this site, we help you to fix...
9 Mar 2018 by BetaEngineer
Hello, I want to know if there is a really good (yet free) software tool which can analyse my C code (which i have written based on PIC and 8051/52 controllers), can find possible coding mistakes and also check MISRA Compliance... What I have tried: I know about PC_LINT, LINT, SPLINT.. but...
9 Mar 2018 by KarstenK
You wont find a good and free code analysis tool. Normally code analysis is included in the IDE in which you are programming. The best way of avoiding bugs is to have some clear, simple and plain program flow. The parameter should be checked at input in your code (like when data is read from...
23 Jun 2019 by Ishayzeb
Suppose there are 5 components, and there is a random supply of each component: ------------------- | Comp | Quantity | |------|----------| | C1 | 500 | | C2 | 700 | | C3 | 400 | | C4 | 1000 | | C5 | 850 | ------------------- And my factory can produce 25...
23 Jun 2019 by Patrice T
Quote: Can someone help find a better approach than a greedy algorithms to this optimization problem? This kind of problem fit in category Integer Programming/Linear Programming, this a NP-Complete problem (hard problem). As Gerry said, for you, the easiest way to solve the problem is probably...
14 Jan 2013 by Qadeer Ahmed Khan
Hi, I am sure following code doesn't look professional so please give some suggestions to make it short.if (((DevExpress.Xpf.LayoutControl.GroupBox)sender).State == DevExpress.Xpf.LayoutControl.GroupBoxState.Maximized){ Employee emp =...
14 Jan 2013 by Jibesh
my suggestions areKeep this '((DevExpress.Xpf.LayoutControl.GroupBox)sender) in a location variable say mySenderreplace all the occurrence of '((DevExpress.Xpf.LayoutControl.GroupBox)sender)' with mySenderif you want go further define another variable for mySender.Content as...
14 Jan 2013 by Daniele Rota Nodari
As Adam R Harris you can use local variables to store data the code access more than once; in your code the variable most used is sender cast to DevExpress.Xpf.LayoutControl.GroupBox; the second one is its Content property.The followin is a possible arrangement:var box = sender as...
21 Jun 2017 by ddgjgj
So these are the methods that handle picture upload in the controller . [HttpPost] [ValidateAntiForgeryToken] public ActionResult Edit([Bind(Include = "AlbumId,GenreId,ArtistId,Title,Price,AlbumArtUrl")] Album album, HttpPostedFileBase file) { if...
21 Jun 2017 by Karthik_Mahalingam
try [HttpPost] [ValidateAntiForgeryToken] public ActionResult Edit([Bind(Include = "AlbumId,GenreId,ArtistId,Title,Price,AlbumArtUrl")] Album album, HttpPostedFileBase file) { return CreateEdit(file, album, false); } [HttpPost] ...
21 Dec 2023 by Fercap89
I need to make a clean copy of a very large object list, about 400,000 records, for this I am doing the following: public static T DeepClone(this T a) { if (ReferenceEquals(a, null)) return default; return...
23 Dec 2023 by OriginalGriff
Stop and think about what you are doing: JSON is a human readable text based transfer format, not an efficient storage format. Suppose your object to deep close was an array of integers, containing five values: int[] data =...
19 Nov 2012 by Christian Graus
If you want us to help you cheat on your homework, then you've misunderstood what this site is for.
15 Aug 2013 by DJ Ballesteros
Hi,Anyone here who will help me to find better tutorials or advise me from tuning my query. I know how to create SQL scripts, stored procedure queries, and the likes. But, I want to be expert with this IT field. I am a Business Intelligence Associate acted as a Software...
15 Sep 2016 by matt warren
Coz: Finding Code that Counts with Causal Profiling - An Introduction
20 Oct 2015 by Sreekanth Mothukuru
In this article, we are going to create an ASP.NET Web Forms application using Bootstrap, Bundle Resources and Web API
3 Mar 2015 by Gold$Coin
Hi,I have a concern about declaring variable(s) inside a for/foreach/while/dowhile loop which would last for more than 1000~10000 iterations. We won’t bother about declaring any number of variables (string[],List, Dictionary) (forgot about creating a custom type and adding to a...
3 Mar 2015 by Sergey Alexandrovich Kryukov
There is nothing wrong with declaring many variables inside loop, as the optimizer can easily take care of it. If all those variables are reasonable, you should not to "manual optimization", such as carrying them out of the loop. Just the opposite, it's good to limit format context of all...
20 Nov 2014 by Ben M Watson
Get into the details of .NET array access optimization and how you can pattern your code for efficiency.
6 Jan 2016 by Anant Beriwal
I have a database of millions of rows. each rows contain one transaction.I have to search how many rows are added/updated in last 24 hours. Table always contains timestamps of modification/addition.Now data beyond 1 days is not useful anyway. If a search is made for records of last 24...
6 Jan 2016 by _Asif_
I have to say that for your purpose deletion is not the right option, Deletion is a costly activity as it has to do so many tasks behind the scene which you probably not aware of (for example index correction, locking, logging, etc).in your case an index over your timespan field will...
5 Jan 2023 by Michael Sydney Balloni
See how Rust stacks up against C-ish, C++, and C#
10 Oct 2020 by Sandeep Mewara
An optimization programming technique
22 Aug 2016 by Sanmayce
Tuned function for searching a needle in a haystack
6 Oct 2014 by Bartlomiej Filipek
Several code changes that made my particle system faster: SIMD, random number generator, pointer aliasing, memory alignment
16 Sep 2014 by Bartlomiej Filipek
In this post, I will test several compiler options and switches that could make the particle system run faster.
24 Oct 2012 by zlristovski
I have table Articles with next structure:ArticleID Price Date1 50 2010-12-231 52 2012-10-222 102 2009-02-062 95 2007-05-302 89 2011-09-123 41 2006-01-213 63 2012-03-16I want to get just the...
24 Oct 2012 by Manas Bhardwaj
What about this:SELECT TOP 1 * FROM Articles ORDER BY Date DESC
24 Oct 2012 by damodara naidu betha
Hi.., I think following query can help you.. SELECT A.ArticleId,A.Cost,A.Date FROM ( SELECT ArticleId,Cost,Date, ROW_NUMBER() OVER(PARTITION BY ArticleId ORDER BY Date DESC) ROWNUM FROM Articles ) AS AWHERE A.ROWNUM = 1 Thank you
23 Feb 2012 by Mahmud Hasan
How to use variable in SELECT TOP SQL command
29 Nov 2014 by Hapisha
how to find the norm of a function of type |XY|function(int n, double **X, double *Y, double *norm){ //write the code to find the norm }where n = number of iterationY = pointer to dX = double pointer to Bnorm = output
29 Nov 2014 by OriginalGriff
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.Try it yourself, you may find it...
30 Nov 2014 by Stefan_Lang
1. look up the formula(s) required to calculate the expected return value from these inputs2. translate these formulas into a series of C/C++ operations; use local variables to hold temporary values if needed3. understand and fix any compiler errors and warnings that you may encounter4....
19 Dec 2019 by Rick York
A simple, header-only class for high resolution timing
5 Aug 2023 by Patrice T
Quote: How can solve nonlinear optimization problem in Python? As is, you are looking for God's Algorithm. This secret algorithm works by just looking at the problem makes the solution jump to your face :) You are careful to give extremely vague...
5 Aug 2023 by aboueshaghi aboueshaghi
Hello everybody. I want to optimize a non-linear expression in Python that cannot be directly entered into the code initially. It needs to be calculated first through matrix operations and then optimized. This expression involves 20 or more...
19 May 2016 by VenHayz
I would like to turn my code into a simpler version. The current seems too complex, and/or too slow to create hundreds of commands. Please explain other ways. I already attempted to put it into a switch statement, but it doesn't work because it's a method, not variable. Example of what I...
18 May 2016 by Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
You can do like below...if(rawCmd.ToLower().Equals("help")){ // Codes here}
19 May 2016 by Patrice T
If you start to check for cases, you need to check all combinations.help, helP, heLp, heLP, hElp, hElP, hELp, hELP, Help, HelP, HeLp, HeLP, HElp, HElP, HELp and HELP.The best solution is to force to lower case or upper case, your choice.public static String ParseCmd(String rawCmd) ...
18 May 2016 by George Jonsson
First of all, your switch statement doesn't work because String.Contains() returns a bool.switch (rawCmd.Contains("Help")){ }should beswitch (rawCmd){ case : "help" : ..; break; case : "heLP" : ..; break; case : "HeLP" : ..; break; etc. default: //...
19 May 2016 by Matt T Heffron
Since you'll have "hundreds, maybe thousands of commands" then I'd suggest using a Dictionary. Something like:private static Dictionary CommandMap = new Dictionary(StringComparer.OrdinalIgnoreCase) { { "Help", "Type a command!" }, {...
21 Apr 2017 by BeginnerCoderPete
dtFilterStartDate = "01/" & DtpMonth.Value.Month & "/" & DtpYear.Value.Year & "" dtFilterEndDate = dtFilterStartDate.AddMonths(1) intEmployee = CmbxEmployeeFilter.SelectedValue AttendanceViewerDataGrid(DgvAttendanceTimesViewer, TblEmployeesBindingSource) ...
25 May 2019 by Salim Hoseini
I have a database with many records from members that each member creates posts for themselves. I want to show daily, weekly, monthly and yearly created posts for each user. What is the best and most effective way to do this? best query and optimize code. Use caching system? What data structure...
25 May 2019 by OriginalGriff
You've already decided the "data structure" by deciding on a database! It is table, column, and row based, so your structure is going to be reasonably flat. Me? I'd have a table for users, and a separate table for posts, which includes a foreign key to the users table. And the Posts table would...
19 Oct 2021 by Weird Japanese Shows
Hello guys. I know, the header is not clear enough. Let me explain the situation in detail. I've a server which takes messages from clients, then check if the message type matches any of the existing types via if - else if(there are more than...
19 Oct 2021 by k5054
At a guess: the strings "test1", "test2", "test3" are all very short and maybe the compiler is smart enough to use a "small string optimization", and ends up comparing 64bit ints rather than doing a string compare. You also have a very small...
21 Dec 2014 by syedkhaleel
Hi folks,I have been trying to cache image resources of my application in client browser.I googled I found different solutions.some at IIS level.some suggested to create custom handlers.but still i have confusion to proceed.As i don't have access to IIS. Is there any best way we can...
21 Dec 2014 by Kornfeld Eliyahu Peter
You can not cache ONLY images without custom handlers...You can control client side caching using web.config settings...It will affect all content of course...http://www.iis.net/configreference/system.webserver/staticcontent/clientcache[^]
21 Dec 2014 by Abhinav S
Nice article - Caching Images in ASP.NET[^].
8 Aug 2018 by Member 13941108
Hello guys. I'm having an issue with a Python PulP MILP problem. You can find the simplified code that reproduces the problem here: from pulp import * machines = 2 I = range(machines) positions = 2 J = range(positions) years = 10 T = range(years) age = {0: 5, 1: 7} IR = 0.06 df = 0.3 costs =...
8 Aug 2018 by Gerry Schmitz
Prob_vars = LpVariable.dicts("probvars", ((Machine, Position,Year, Age) for Machine in I for Position in J for Year in T for Age in range(age[i])),0,None, LpInteger) You're iterating over "Machine" twice in the inner loop while holding index "i".
21 Oct 2016 by Member 12643245
Hi Developers, I have been working on a music player for a while now, but i have been having problem with speed. The music player loads every mp3 file in the music folder and at that same instance also getting the metadata and cover art for the picture. Is there anyway to make this...
21 Oct 2016 by OriginalGriff
There is no "one size fits all" approach which we can tell you "do this, it'll be fine" - but you may want to look at background and / or "as required" loading.start by identifying where the bottlenecks are: without n=knowing that you have nowhere to focus your attention. So use the Stopwatch...
11 Jan 2015 by Member 10809057
in my data base i've 7L records,in my web page i have auto complete text box it take to much time to get the records from database, plz suggest me searching make easier
11 Jan 2015 by Wendelius
If I understood the question correctly, you could- start suggesting values only when you have enough characters in the auto complete text box (3 perhaps?)- make sure that you have proper indexing in place that helps to fetch the data- if the data is static, utilize caching- utilize...
22 Nov 2013 by Gabriel Sas
is there a differents between these codes on speed on how the compiler create the .exe ?String s = Object1.Object2.GetCustomerName();// the Name can also be a PropertyCallMethod(s);and CallMethod(Object1.Object2.GetcustomerName());The second would just have less code if this...