Click here to Skip to main content
15,890,438 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 

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...
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...
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,...
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)...
21 Dec 2014 by Abhinav S
Nice article - Caching Images in ASP.NET[^].
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...
14 Jun 2014 by Aescleal
You could try writing C++ and use std::vector and std::generate(). Only if that's too slow consider managing memory yourself. Even if you need to manage memory yourself then use std::unique_ptr to automagically sort out releasing the memory.
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...
18 Apr 2014 by Ali_100
SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOALTER PROCEDURE [dbo].[usp_DeleteRoadMapRelations] -- Add the parameters for the stored procedure here @RoadMapGuid uniqueidentifier, @StatusMessage varchar(50) OUTPUT ASBEGIN -- DELETE RoadMap...
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...
3 Apr 2014 by Amol_B
Dear All,Greetings.Could you please let us know your thoughts on below problem:We are using SQL 2012 Enterprise Edition in our ERP application.We have around 40 GB of database in the same which is kind of Datawarehouse.There is import process which runs daily on the server...
21 May 2014 by Amol_B
Hello ,I use sql2008 R2. One my my table contains more than 10,000,000 records with data size around 4.2 GB.This table Contains data about inventories and its properties.A select * for table query takes 27 Minutes Retrieve data.I am using this table with inner joins with another table...
12 Jun 2014 by Amol_B
Thanks Muli G for sharing link.MSDN link[^]
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...
12 May 2014 by Andrew Torrance
As in all things ... It depends . I am assuming that this is a mature working system ? There is a school of thought that says that business logic such as this is best kept out of SQL . I have no idea of the systems that are using this ,but ideally the logic in here would be handled in the...
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...
31 Jul 2015 by Android on Intel
This blog covers some Tips and Tricks on memory optimization and working with textures and was compiled by Steve Hughes who works as an Applications Engineer for Visual Computing at Intel.
15 Apr 2013 by Angela Lucchesi
My job is to create and store reports created from log table. Application is in production for a few years now. After a while as log grows report generation becomes slower. Our solution was to delete some records from a log table after a while. I have the source code of application and I need to...
18 Nov 2013 by Arnaldo P. Castaño
This document describes a tabu Search algorithm embedded in a multiobjective framework capable of finding solutions to the zoning problem by allowing the optimization of multiple objectives.
17 Apr 2013 by Bartlomiej Filipek
Experiments about compilation times and file structure in C++, using GCC, MinGW, Visual Studio.
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.
6 Oct 2014 by Bartlomiej Filipek
Several code changes that made my particle system faster: SIMD, random number generator, pointer aliasing, memory alignment
21 Apr 2017 by BeginnerCoderPete
dtFilterStartDate = "01/" & DtpMonth.Value.Month & "/" & DtpYear.Value.Year & "" dtFilterEndDate = dtFilterStartDate.AddMonths(1) intEmployee = CmbxEmployeeFilter.SelectedValue AttendanceViewerDataGrid(DgvAttendanceTimesViewer, TblEmployeesBindingSource) ...
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 2022 by Bernhard Nebel
Link-time optimization and debugging OO programs do not work very well together, at least on AVR MCUs.
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...
13 Jan 2015 by BillWoodruff
imho, this only becomes really interesting when the stock of boards you have to fill an order with contains boards of varying lengths. If your stock is always only 12-meter boards, it is a much simpler optimization.Have you started trying to design classes/data-structures for this, or...
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...
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...
15 Apr 2013 by bobb024
Hey All,so I have a console application written in C# and I was under the impression that I would have multiple files and could insert them all at once. As we all know, things and specs change. Instead of having about 1000 files and being able to spawn a new thread to download and process, I...
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 ?
14 Jun 2014 by BupeChombaDerrick
For illustration purposes, I have a data structure as shown below. What is the fastest Code 1 or Code 2?struct Array{// length of arraypublic: int length;// pointer to int arraypublic: int *pData;// allocate arraypublic: bool allocate(int size);// constructorpublic:...
21 Feb 2018 by Charles Oder
To optimize, or not to optimize, that is the question...
12 May 2014 by Chathur
I have following stored procedure written in a C# win forms application which calculates employee earnings based on attendance as follows. Note that a shift is 12 hours and employees mark attendance for in and out of each shifts. Also salary period is from beginning to end of a month (1st to...
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--,...
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.
6 Aug 2014 by coded007
Try with below query i am not sure it will give data under 5 seconds but performance will improve.create table #oz ( id int, from_sto_move bit, product_id int, [date] datetime, qty_orlogo decimal(30, 10), qty_zarlaga decimal(30, 10), cost_prev decimal(30, 10)) print 'Query started...
14 Jun 2014 by CPallini
As already suggested, if in doubt, make the compiler generate the assembly codes for you and then compare them. With a decent compiler there should be no difference.
28 Oct 2014 by CPallini
While you probably can't either optimize or make it more elegant, you might fix it (you are using uninitialized variables).
8 Jun 2020 by D Sarthi Maheshwari
Discussing about streams... about streaming... about functional streaming... and nothing else
11 Mar 2019 by D Sarthi Maheshwari
Discussing about streams... about streaming... about functional streaming... and nothing else.
19 Mar 2015 by d.vasegh
Hi,I developed a logger for data gathering from external device. it should record some data (int x6, string x4) once per second and supposed to run 24x7. for the first 24 hours everything is fine but then it hang over and the only thing that i can do is to restart whole system.is there...
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
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...
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...
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...
15 Apr 2013 by db7uk
Hi,I think I like where this is going. Your speed will be down to the inserts into SQL as we all probably know. One way to really improve performance is bulk inserts but you mention that you have tried this before but no luck.You have not mentioned what .Net framework version you are...
15 Apr 2013 by db7uk
Hi me again.I am interested to find out what went wrong with bulk inserts.Have you also looked at:1) Generate your chunk files as explained in solution 1. Instead of inserting into a database directly consider writing the file(s) to a folder/directory.2) Using SSIS to read the...
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 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...
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...
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...
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 :(...
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...
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...
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...
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...
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...
13 Jan 2015 by GeekGirl90
I have a stock of wooden boards which are 12 meters long.If I get an order for a set of boards of different lengths, I want to calculate how to cut the minimum number of 12-meter boards to get the set of boards ordered, with as little loss as possible.This should work with all orders,...
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: //...
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".
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.
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 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...
13 Aug 2014 by Gihan Liyanage
See this links. It will help you.http://msdn.microsoft.com/en-us/library/ms182539.aspx[^]http://msdn.microsoft.com/en-us/library/dn250793.aspx[^]
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...
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
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,...
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...
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
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...
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....
7 Jun 2011 by iceball12
I get an error when calling a com object.Somehow when i have optimize code disabled there seems to be a difference between debugging and just running the debug build.When debugger is attached from startup it crashes with the AccessViolationException.When debugger is attached after...
8 Sep 2020 by Iqra Ali
The article explains the concept of Sanity Testing and the implementation using TestNG features.
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...
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...
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...
2 Apr 2013 by JustDaveL
So I have this function and it works and does exactly what I need it to do, however; the function is extremely slow...not minutes slow but, I imagine it could get there as the files I receive get larger. I just need a few suggestions to steam line or optimize the function to process just a...
12 May 2014 by Jörgen Andersson
Firstly, there are lots of conversions happening everywhere which implies that Attendance.in_time is stored in the wrong format.If fixing that isn't possible you can consider using a CTE that selects and aggregates the needed data in the necessary format and then use this in a secondary...
21 May 2014 by Jörgen Andersson
I'm seeing two errors here.Firstly average usage and consumption per item is aggregation of data.Filtering and aggregation is what the database excels at. So why on earth do you want to move the whole bunch of data off the database. Do your aggregation in the query.Were having a database...
28 Jun 2016 by Jörgen Andersson
Stored procedures and dynamic queries don't mix well.First time you're using the procedure it will be compiled and optimized for the parameters you used on that occasion.If you the next time use different parameters, the query plan will not be optimized.I recommend in this case that you...
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...
15 Jun 2014 by KarstenK
in a release build both solution should have the same speed, because optimization.Code 3:Array array(10000);int l = array.length;int *pData = array.pData;for(int i = 0;i
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...
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;
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....
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] ...
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...
21 May 2014 by Kornfeld Eliyahu Peter
There are a few things you can do (and I deal with historical data with over 560.000.000 records so far).1. Make your table partitioned, probably over some column of date. That can help SQL to scan index pages only for a specific time frame.2. Choose carefully your clustered index. The...
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[^]
30 Jun 2014 by Kunal Ved
I have got a query , which has lot of inner query nested into it, Although it gives me a correct report but however it takes too long(several minutes) to execute to execute.Is there any way to optimize the same .Following is the query written as a stored Procedure.CREATE PROCEDURE...
28 Jun 2016 by Kunal Ved
Hi ,I have a query written in quite old fashioned manner in a Store ProcThe Store Proc uses 2 tables , FOLLOWUP_DETAILS which has 231352 records and TELE_ENQUIRIES which has 91727 number of records.The search filter is just done based on date range of 1 monthFor...
23 Jul 2015 by Lalyka
I have 2 queries that it stuck and never finish Can anybody help me? I am trying to avoid a foreach and because of this I want to use the linked queriesI want ret1 search for all the data in q1Thanks in advancevar q1 = Filter.Number.Select(item => new { ...
15 Apr 2013 by Lucas Valeriy
Best idea I know of is to keep your log in multiple tables. I guess you need to do a report only for defined time scope. Keep fresh data in one table and older data in different table. Your report generation time will be reduced.Try pre-processing the data and then keeping only the report...
21 May 2014 by Maciej Los
Amol_B wrote:My Question is, is there any by which we can load large data(greater the 3 GB ) within a minute ?(...)A select * for table query takes 27 Minutes Retrieve dataNo, there is no method to load 10 millions records within one minute even if you add indexes, make partitioned your...
17 Sep 2016 by Maciej Los
I'd suggest to read about CTE. See:WITH common_table_expression (Transact-SQL)[^]Using Common Table Expressions[^]Recursive Queries Using Common Table Expressions[^]CTE's on CP KB[^]
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...