Click here to Skip to main content
15,881,580 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 Score

Optimization 

10 Oct 2020 by Sandeep Mewara
An optimization programming technique
1 Jul 2023 by Ryan Scott White
A fast, possibly the fastest, square root function for Big Integers and Floats in C# and Java.
23 Feb 2012 by Mahmud Hasan
How to use variable in SELECT TOP SQL command
8 Jun 2020 by D Sarthi Maheshwari
Discussing about streams... about streaming... about functional streaming... and nothing else
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.
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...
16 Sep 2016 by matt warren
In my previous post, I talked about some of the general performance lessons that can be learnt from the Roslyn project. This post builds on that and looks at specific examples from the code base.Generally the performance gains within Roslyn come down to one thing: Ensuring the garbage colle
19 Dec 2019 by Rick York
A simple, header-only class for high resolution timing
10 Jan 2013 by Zamshed Farhan
APC is a very popular PHP extension to optimize PHP developments.
22 Nov 2013 by Sergey Alexandrovich Kryukov
In addition to other answers: I would advice you to focus on code maintenance and readability and ignore the possibilities for such small "optimizations": most usually, they won't actually "optimize" anything. As to the readability differences between your two samples, there is no clear...
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...
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...
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...
7 Mar 2024 by Michael Sydney Balloni
A "new" queue data structure is described and compared with existing collection types
12 Jul 2012 by StianSandberg
An extension for minimizing HTML output from a partial view
23 May 2013 by Pavlo Iarovyi
Visual Studio extension to change Visual Studio "hidden" option for project loading to reduce loading time for big solutions.
23 May 2013 by Pavlo Iarovyi
Visual Studio extension to change "hidden" option for project loading to optimize loading big solutions.
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.
22 Nov 2013 by OriginalGriff
In practice? No, not in release versions - the intermediate variable will be optimised out.In debug versions there is likely to be a difference as debug versions generally do not employ as aggressive optimisations, if it uses any at all.You can check for yourself: this explains how to view...
22 Nov 2013 by Ron Beyer
Compile it and see!You can easily compare compiled exe's using ildasm (Intermediate Language Disassembler) that is included with Visual Studio. Also another fun trick is to compare two of exactly the same programs, one compiled for Debug, and the other compiled for Release.As far as...
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.
15 Sep 2016 by matt warren
Coz: Finding Code that Counts with Causal Profiling - An Introduction
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...
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...
11 Mar 2019 by D Sarthi Maheshwari
Discussing about streams... about streaming... about functional streaming... and nothing else.
8 Sep 2020 by Iqra Ali
The article explains the concept of Sanity Testing and the implementation using TestNG features.
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...
6 Jan 2022 by Bernhard Nebel
Link-time optimization and debugging OO programs do not work very well together, at least on AVR MCUs.
30 Nov 2012 by Sergey Alexandrovich Kryukov
By apparent reasons.For an unconditional breakpoint, you can seed a hardware instruction(s) to call a debugger. In particular, on x86, x86-64 or IE-64 instruction set architectures, there is a hardware support of debugging, and the interrupt instruction can be used to set a breakpoint....
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...
30 Jun 2013 by Zoltán Zörgő
Transportation problems can be solved with simplex method.And there is the Microsoft Solver Foundations[^] also, that can be used for transportation problems. Look at this example: http://www.sommer-forst.de/blog/2012/10/24/solving-network-flow-models-2-microsoft-solver-foundation/[^]
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 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[^]
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.
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
6 Oct 2014 by Bartlomiej Filipek
Several code changes that made my particle system faster: SIMD, random number generator, pointer aliasing, memory alignment
28 Oct 2014 by PIEBALDconsult
There's not much to that. At most, all you can strive for is "more readable". What you show requires a lot of scanning up-and-down to spot the differences between the then and else parts. Have a look at the following; just putting the assignments in closer proximity can make the differences more...
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....
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...
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.
11 Oct 2015 by Patrice T
There is not possible answer to your question.Any swarm algorithm may be suitable or not !Because swarm algorithms are general purpose, they don't do face recognition by them self, you must relay on a face recognition algorithm. Swarm algorithms are about speeding up things only.Your...
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: //...
26 Jun 2016 by ZurdoDev
There is no way we can tell you how to speed it up because we cannot access your system. However, some things to look for are:1. Make sure there are indexes on the fields you are joining on.2. Indexes on fields in your where clause would be a good idea; however, because all of your...
17 Jan 2017 by Michael_Davies
You do not need to cast, .GetInt32 returns an 32 bit integer, .String returns a string.The only cast you need is the one to convert the int to a string if you need it as a string.Acct_ID = rdr.GetInt32[0].ToString + " " + rdr.GetString[2];
21 Jan 2017 by OriginalGriff
That's not good. You are doing a number of nasty things there.First off you are using class variables for things that should be local: your connection and reader. Worse, they are static!You are using a using block for your command, but manually closing the reader.You are doing irrelevant...
3 Feb 2017 by Pete O'Hanlon
The problem with the question you are asking is that it's largely subjective and dependent on the ability/skill level of the person reviewing your code (no, those two things don't mean the same thing). What you are really after is a code review where someone points out what is good and bad about...
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] ...
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...
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".
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;
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...
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...
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...
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...
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...
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...
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....
27 Jul 2012 by patelv61
I am working on one query with was gifted to me to work on has 3 group by and one function. THis query takse more than 15 minutes and end user can't wait that long I already have done several thing includes:(1) Performance Tunning, (2) Rewrite Index(Clustered and nonclustered)
27 Jul 2012 by shravenreddy
Use Sqlprofiler , Database tuning Advisor and use Unique index is better way to increase performance.
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 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
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.
30 Nov 2012 by Yvan Rodrigues
So I'm debugging some code an I notice some odd behaviour when type == "CSSRule". Ok I figure, I'll add a conditional breakpoint. Stop in this method when type == "CSSRule". /// /// Gets the type. /// /// The...
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
2 Apr 2013 by Matt T Heffron
Like others said.Here it's "consolidated":bool? dialogResult = _openFileDialog.ShowDialog();if (dialogResult.HasValue && dialogResult.Value){ FilePath.Text = _openFileDialog.File.FullName; string[] allLines = File.ReadAllLines(FilePath.Text); // read the file only ONCE ...
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...
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 Apr 2013 by Sandeep Mewara
It does not work like this here.Here is what is expected of enquirers:1. TRY first what you want to do! You may find that it's not that hard.2. Formulate what was done by you that looks like an issue/not working. Try them and tell if you face issues.Members will be more than happy...
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[^]
20 Mar 2014 by npdev13
Hello,I have one application which is using MS SQL 2008 database.In the database I have one long storeprocedure which is doing many operation like reading some of the tables and check some specific record exists or not, if not exits then it create the record other wise update it, these...
27 Mar 2014 by npdev13
Hello,I have found the solution of the issue which I was facing.By Adding the sp_getapplock statement at first statement of sp and sp_releaseapplock at last statement of sp it resolve my issue.I've added it like below :CREATE PROCEDURE [dbo].[TestSP]ASBEGIN BEGIN...
20 Apr 2014 by thatraja
Agree with NeverJustHere. 0) Avoid Cursors. Cursor alternatives[^]1) And improve the exception handling.Overview of Error Handling in SQL Server 2005[^]A Closer Look Inside RAISERROR - SQLServer 2005 [^]2) Use EXISTS instead of IN for DELETE queries.N) Check this answer, I have...
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...
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:...
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...
30 Jun 2014 by Magic Wonder
Hi,Your query can be optimized by you only. It seems that so many left outer will obviously slow the output. If you can either avoid so many left outers or make small small chunks of cases to fetch out data and then fetch the Final output.Cheers.
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...
13 Aug 2014 by ravikhoda
Hi all,i have a project running on .Net framework 4.0 , c# asp.net and sql 2008 r2. i want to check the performance of the site. i have made some changes to queries and code to load a grid view with thousands of records , remove some unwanted code and modify some existing code based on the...
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[^]
28 Oct 2014 by Philippe Mori
For the efficiency, I would usually do something similar to original code.For elegance, you could write:var c = Math.Max(a, b);var d = Math.Min(a, b);Alternatively, the following patern could sometime also be used:var c = a;var d = b;if (c
29 Oct 2014 by Member 10933212
I am new to Particle Swarm Optimization and trying to write a code in octave.swarm_size=10; %number of the swarm particlesmaxIter = 50; %maximum number of iterationsinertia = 1.0; %i dont know what it doescorrection_factor = 2.0 ; % i dont know what it does...
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...
18 Dec 2014 by syedkhaleel
Hi folks,I am implementing bundling and minification in my application.I am able to combine resource.But I dont see any minification is applied to bundled folder.It is not clearing the comments in js/css files and not optimizing the content of the files.Please share your thoughts on...
18 Dec 2014 by virang_21
If you are debugging your application from VS it will not happen in debug mode. You can enable this by adding BundleTable.EnableOptimizations = true; in your RegisterBundles method (BundleConfig class in the App_Start...
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[^].
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...
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...
6 Feb 2015 by Member 11423699
Hello!When I use PageSpeed Insights the results is really bad. I would need to optimize my photos on my website, have tested some programs but haven't find any good (use Mac OS X) . Does anyone have good tips? :)/Oscar
6 Feb 2015 by ZurdoDev
#5 at http://browserdiet.com/en/[^] has a link for some by clicking on the Useful Tools link.
10 Feb 2015 by syedkhaleel
I am trying to publish my website to deployment server.Which includes changes to global.asax file's application_start.which registers a bundle to load/compress js/css files.it works fine with local solution and IIS 7 version on server.But when I deploy same application to server with IIS 6...
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...