Click here to Skip to main content
15,891,607 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 Updated

Optimization 

7 Mar 2024 by Michael Sydney Balloni
A "new" queue data structure is described and compared with existing collection types
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 =...
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...
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...
1 Jul 2023 by Ryan Scott White
A fast, possibly the fastest, square root function for Big Integers and Floats in C# and Java.
5 Jan 2023 by Michael Sydney Balloni
See how Rust stacks up against C-ish, C++, and C#
30 Aug 2022 by H. G. Aug2022
Hi, I wrote a code in Gurobi Python API for minimizing production costs which have a variable and a fixed cost part. There are a number of tasks which are assigned to a number of stations whereby cycle time should not be exceeded. Also 4 types of...
22 Jun 2022 by Stephane Capo
C++ optimization for map using string key among others
9 Feb 2022 by Member 15530401
I have a neural network model (model.predict in code) which fitted our data, and now we want optimized some variables that exist in the model. my code are attached below, def objective_function(X): wob = X[0] torque= X[1] RPM = X[2] ...
6 Jan 2022 by Bernhard Nebel
Link-time optimization and debugging OO programs do not work very well together, at least on AVR MCUs.
27 Dec 2021 by Member 15481823
I wanted to make a code that, when receiving data, process them in turn, and not just write them all into one list. Because in cases where numbers reach 2000 characters in length, the code consumes a lot of memory (allocated for this task). Here...
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.
29 Oct 2021 by Patrice T
Quote: How to optimize this code for speed any further Assuming the Elo ranking is positive values only: - At cost of count a little larger, min can be just removed from code. Assuming you know the range of values of Elo: - you can set max to a...
29 Oct 2021 by Weird Japanese Shows
Hello, I'm using counting sort for sorting elo rating of players, I've compared many different sorting techniques and decided to use counting sort. Even if counting sort is a little slower than insertion sort, because it's more stable and...
28 Oct 2021 by Rick York
Regarding your comments - they do not explain why you need to use shared_ptr. If you control the lifetime of the objects then you can safely use unique_ptr. I always make sure that I do (control object lifetimes) so I never, ever use shared_ptr...
28 Oct 2021 by Greg Utas
You could try creating locals for r.size() and count[r[i]->elo - min], but it probably won't matter if you're using a decent optimizing compiler. There's probably some overhead caused by boost::shared_ptr. A unique_ptr would be slightly faster,...
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...
28 Aug 2021 by RegularJoe5150
A reformulation of compressed pair into a type list
2 Jul 2021 by Slow Eddie
I read somewhere that optimizing an SSD drive was harmful to it. Do you know if this is correct? It is a 10TB Raid5 NAS. Please let mo know if you do. What I have tried: Nothing yet. I am in the process of searching the web, as I feel you...
2 Jul 2021 by Patrice T
Quote: I read somewhere that optimizing an SSD drive was harmful to it. Do you know if this is correct? In fact, first question is "what is optimization with SSD ?". Optimization is initially related to HD. With HD, what downgrade performance is...
2 Jul 2021 by Dave Kreskowiak
Uhhh... only if you want to deplete the spare block pool. SSDs have spares because the blocks that make up the capacity of an SSD can only be written so many times before they fail. So, if you're going to "optimize" an SSD, you're going to be...
2 Jul 2021 by OriginalGriff
If you mean defragging it, then long-term yes it does. SSD "wears out" as you write to, it and defragging moves data around to make it simpler for rotating disks to access without extra seek operations. SSD's don't have seeks - no heads to move...
26 Apr 2021 by mrinalbh
I have a query generated from a MSTR report which needs to be run to look into 300+ product ids. The product id is a prompt in the report and hence is always in a where condition and in several different passes like this: where (a19.list_nbr in...
26 Apr 2021 by Wendelius
Unfortunately I'm not familiar with Netezza but I'd like to share some thoughts in general. Very often IN comparison has a maximum number of items you can place inside the comparison. While 300 doesn't sound so many I'd run some tests just to...
17 Dec 2020 by Bob Jason Tiamsic
Hope someone could help me. Our client has an existing database and this specific view is problematic and runs really slow. This has been raised to us as consultants and I saw the execution plan with clustered index scan everywhere. I managed to...
17 Dec 2020 by Gerry Schmitz
I'll go out on a limb and call the index design a joke. I've seen 2 or 3 field indexes; but never 13 columns! Someone is using indexes to "sort" data; from the looks of it. Someone needs to justify these indexes (which I don't think they'll be...
10 Oct 2020 by Sandeep Mewara
An optimization programming technique
8 Sep 2020 by Iqra Ali
The article explains the concept of Sanity Testing and the implementation using TestNG features.
30 Aug 2020 by Member 11166599
Hello, I have a mysql table that stores data about the presence of a sensor at each timestamp, in multiple areas. If I have for example 3 areas, for a certain timestamp, my table will look like this: timestamp areas_id ...
30 Aug 2020 by Maciej Los
Sorry, but the description of issue is not quite clear, because: 1) if you want to get min and max values for timestamp field, you don't need to write several subqueries (for each areas_id); the group by statement is doing it already, 2) if you...
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...
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...
9 Jul 2020 by HB World
Question : We have been given two arrays of size N with each element as hi, ai the elements are positive integers and random. We are Also Given with Q queries of 2 type. In query type 1 : we will be given with 2 positive integers b k and we...
9 Jul 2020 by KarstenK
Q1 is an changing task, but it only changes one value. So you can store the Q2 results in an array and only make an update of the sum data in case of Q1 with the difference . With memcpy you can copy a bunch of sum-elements of the result array....
8 Jun 2020 by D Sarthi Maheshwari
Discussing about streams... about streaming... about functional streaming... and nothing else
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".
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...
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...
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...
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...
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 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 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...
19 Dec 2019 by Rick York
A simple, header-only class for high resolution timing
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...
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...
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 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...
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...
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...
23 Apr 2019 by OriginalGriff
Start by profiling it and finding out where it spend most of it's time - then concentrate your efforts on improving that code. Once you have profiled it, you should have a set of numbers which tell you how much time it is taking in its various bits, and re-running the profiler will tell you how...
23 Apr 2019 by Member 14323238
I need to optimize a lot of code, is there anything I can do here? import heapq import math import sys import queue from .util import debug_write class Node: """A pathfinding node Attributes: * visited_idealness (bool): Have we visited this node during the idealness...
11 Mar 2019 by D Sarthi Maheshwari
Discussing about streams... about streaming... about functional streaming... and nothing else.
12 Feb 2019 by dyeung
Hi, I am using C# and the Solver to fit a 2D Gaussian. Using simulated data (no noise) with various sigmas, intensities and center, it was working perfectly. However, with real data, it works only about 50% of time even though all the test data are images of about the same quality and approx....
12 Feb 2019 by dyeung
Thanks for the response. I have gone through the debugger. But the optimizing code doesn't show you the actual run except the 'variables' defined without actual values so there is no way (as I know of) to figure out what is happening during optimization. The data and code are very simple. Can I...
12 Feb 2019 by Patrice T
Quote: It is such a simple problem, I don't think the Solver can't handle it and the data are not that noisy at all. It must be something subtle that I didn't construct the model properly. your code work depending on data, we have no way to find what is wrong without that data. Your code do...
12 Feb 2019 by Gerry Schmitz
Quote: When failed, it failed with values of sigmas and intensity both close to 0.0. Keep testing and find out "where" it fails; "close to" is only good in horse shoes.
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;
10 Oct 2018 by Member 14015042
We have two operations that can be performed in a number: 1. n = n + d.[ both n and d are given as input ] 2. n = sumofdigits(n) We have to find the minimum value of n and minimum number of steps to get to that value. Now, I thought of an algorithm that stores the minimum values of n. Now the...
18 Aug 2018 by Member 13941108
I have the results of an optimization run in the form found in the following pic: https://i.stack.imgur.com/pIA7i.jpg. How can I multiply the dictionary values of the keys FEq_(i,_j,_k,_l) with preexisting values of the form A[i,j,k,l]? For example I want the value of key 'FEq_(0,_0,_2,_2)'...
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".
23 Jul 2018 by Patrice T
Quote: 0 down vote LOL Quote: This question was recently ask in a contest which is now over These contest are especially designed to challenge your skills, so you got the answer: You are unable to solve it. Quote: I tried to solve it by brute force but it give TLE brute force is never the...
23 Jul 2018 by Aman Rawat
0 down vote favorite This question was recently ask in a contest which is now over, but they don't share the editorials with us and this question is stuck in my mind and i am not able to get the answer in optimal way, anybody please explain the proper approach for this is very helpful-:(And if...
23 Jul 2018 by OriginalGriff
So, you've posted this on stack exchange: programming practices - Solving Safe Breaking - Software Engineering Stack Exchange[^] And stack overflow: python - Solving Safe Breaking - Stack Overflow[^] And how because they won't do your homework you bring it here. Guess what? We don't do your...
29 Jun 2018 by Patrice T
Quote: Is there an efficient algorithm for this problem? None, even worse there can be no solution because of infinite looping. Quote: The graph can have cycles, the edge weights could be negative, and the path is allowed to go through a vertex or edge more than once. The combination of those...
29 Jun 2018 by Alexandre Cornet
In my economics research I am currently dealing with a specific shortest path problem: Given a directed deterministic dynamic graph with weights on the edges, I need to find the shortest path from one source S, which goes through N edges. The graph can have cycles, the edge weights could be...
27 Apr 2018 by Wendelius
Without having the whole schema and the data it's impossible to give exact solutions, but some advice: - Use the Management studio to see the execution plan and investigate if proper indexes are used - Also have a look if missing indexes are listed - You have quite a lot of inline view. SQL...
27 Apr 2018 by chimcham
Can anyone help me on how can i optimize my query below. It takes more than a minute just to show 50K records. TIA. What I have tried: This is my query. with cte as ( select batch,lcoDt,runID,erpIO,style,article,leadtm,cfm_tag,EETA, asIO,planDt, class, pono,mainFab,matLeadTm,ExMillDt--,...
21 Mar 2018 by Member 13740593
I am trying to find the best way to optimise the converters below to follow the flow I call 'convertAndGroupForUpdate' first which triggers the conversions and relevant mappings. Any help to optimise this code would be massively appreciated. public List...
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...
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...
21 Feb 2018 by Charles Oder
To optimize, or not to optimize, that is the question...
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...
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...
7 Jan 2018 by mhd.sbt
please Dont Use Temptable Because Of Performance Issue ، I have A time With A cardNo that i want to found Related Personnel Base On some Effective Date. each Personnel can have Multiple EffectiveDate With Diffrent CardNo CREATE PROCEDURE...
7 Jan 2018 by Thava Rajan
Hopefully, try the analytical functions[^]
1 Jan 2018 by Member 13601913
i want to make image optimization some thing like plugins or addon or any thing help me on that !!!!! What I have tried: i cannot find anything but find for WordPress and not found for php website anyone can help me please ??
1 Jan 2018 by Richard MacCutchan
image optimization - Google Search[^]
12 Dec 2017 by Miguel Diaz Kusztrich
A very fast and simple algorithm to solve a Sudoku using boolean operations
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 :(...
26 Sep 2017 by Joe Doe234
Hi all, I have a for loop that I wish to optimize, someone can help me or give me some tricks to optimize string sql1 = "select * from (select distinct left(start_bin_value,6) from sys_mast_inter_bin_table mast join cht_card_brand cb on mast.card_brand = cb.index_field join cht_country ctry...
26 Sep 2017 by Patrice T
string sql1 = "select * from (select distinct left(start_bin_value,6) from sys_mast_inter_bin_table mast join cht_card_brand cb on mast.card_brand = cb.index_field join cht_country ctry on mast.bin_country = ctry.index_field join cht_service_type st on mast.service_type = st.index_field where...
26 Sep 2017 by Graeme_Grant
txtRandCardNumbers.Text += textCardNumber[cx] + Environment.NewLine; I would use StringBuilder[^] var sb = new StringBuilder; for (int cx = 0; cx
5 Sep 2017 by Abderrahim Ben
Short-circuit evaluation is a straight forward subject for lazy evaluation on Boolean expressions, I noted that two factors could be useful for ordering Boolean functions to gain run-time. But this is applicable in a particular hypothesis: Knowing a percentage of positive (hence negative)...
5 Sep 2017 by Patrice T
Quote: Let's say F is a Boolean function that scores sentiment and returns -1 or 1. First of all, Boolean values are 0 for False and 1 for True. In computers, the usage to use 0 for False and non 0 for True. Quote: Short-circuit evaluation is a straight forward subject for lazy evaluation on...
25 Aug 2017 by Abderrahim Ben
For example we want to calculate mean of a list of numbers where the list is so long. and that numbers when sorted are nearly linear (or we can find a linear Regression Model for data). Mathematically we can aggregate mean by ((arr[0] + arr[length(arr)]) / 2 ) + intercept Or in the case,...
25 Aug 2017 by Patrice T
Quote: Is there a form of lazy evaluation where a function (like mean) returns an approximate value when operating on arrays NO, it is a matter of common sense. Mean calculation the algorithm adds all values and divide total by number of values. And it gives exact answer, always, no matter what...
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 Apr 2017 by BeginnerCoderPete
dtFilterStartDate = "01/" & DtpMonth.Value.Month & "/" & DtpYear.Value.Year & "" dtFilterEndDate = dtFilterStartDate.AddMonths(1) intEmployee = CmbxEmployeeFilter.SelectedValue AttendanceViewerDataGrid(DgvAttendanceTimesViewer, TblEmployeesBindingSource) ...