optimization

Java for-loop optimization

北战南征 提交于 2019-12-28 06:49:29
问题 I made some runtime tests with java for loops and recognized a strange behaviour. For my code I need wrapper objects for primitive types like int, double and so on, to simulate io and output parameters, but thats not the point. Just watch my code. How can objects with field access be faster then primitive types? for loop with prtimitive type: public static void main(String[] args) { double max = 1000; for (int j = 1; j < 8; j++) { double i; max = max * 10; long start = System.nanoTime(); for

Finding the most frequent character in a string

北战南征 提交于 2019-12-28 06:46:37
问题 I found this programming problem while looking at a job posting on SO. I thought it was pretty interesting and as a beginner Python programmer I attempted to tackle it. However I feel my solution is quite...messy...can anyone make any suggestions to optimize it or make it cleaner? I know it's pretty trivial, but I had fun writing it. Note: Python 2.6 The problem: Write pseudo-code (or actual code) for a function that takes in a string and returns the letter that appears the most in that

How do I ask for help optimizing & fixing queries in MySQL?

吃可爱长大的小学妹 提交于 2019-12-28 06:20:47
问题 MySQL questions are some of my favorites on StackOverflow. Unfortunately, things like this: SELECT foo, bar, baz, quux, frozzle, lambchops FROM something JOIN somethingelse ON 1=1 JOIN (SELECT * FROM areyouserious) v ON 0=5 WHERE lambchops = 'good'; make my eyes bleed. Also, attempts at describing your schema often go like this: I have a table CrazyTable with a column that is a date and it has a primary key of Foo_Key but I want to join on SOMETABLE using a substring of column_bar (which is

XSSFWorkbook takes a lot of time to load

别来无恙 提交于 2019-12-28 05:56:25
问题 I am using the following code: File file = new File("abc.xlsx"); InputStream st = new FileInputStream(file); XSSFWorkbook wb = new XSSFWorkbook(st); The xlsx file itself has 25,000 rows and each row has content in 500 columns. During debugging, I saw that the third row where I create a XSSFWorkbook, it takes a lot of time (1 hour!) to complete this statement. Is there a better way to access the values of the original xlsx file? 回答1: First up, don't load a XSSFWorkbook from an InputStream when

XSSFWorkbook takes a lot of time to load

喜夏-厌秋 提交于 2019-12-28 05:55:28
问题 I am using the following code: File file = new File("abc.xlsx"); InputStream st = new FileInputStream(file); XSSFWorkbook wb = new XSSFWorkbook(st); The xlsx file itself has 25,000 rows and each row has content in 500 columns. During debugging, I saw that the third row where I create a XSSFWorkbook, it takes a lot of time (1 hour!) to complete this statement. Is there a better way to access the values of the original xlsx file? 回答1: First up, don't load a XSSFWorkbook from an InputStream when

fast way to check if an array of chars is zero [duplicate]

浪子不回头ぞ 提交于 2019-12-28 05:28:28
问题 This question already has answers here : Faster approach to checking for an all-zero buffer in C? (20 answers) Closed 11 months ago . I have an array of bytes, in memory. What's the fastest way to see if all the bytes in the array are zero? 回答1: Nowadays, short of using SIMD extensions (such as SSE on x86 processors), you might as well iterate over the array and compare each value to 0. In the distant past , performing a comparison and conditional branch for each element in the array (in

How to speed up floating-point to integer number conversion? [duplicate]

最后都变了- 提交于 2019-12-28 05:10:12
问题 This question already has answers here : What is the fastest way to convert float to int on x86 (10 answers) Closed 5 years ago . We're doing a great deal of floating-point to integer number conversions in our project. Basically, something like this for(int i = 0; i < HUGE_NUMBER; i++) int_array[i] = float_array[i]; The default C function which performs the conversion turns out to be quite time consuming. Is there any work around (maybe a hand tuned function) which can speed up the process a

requestAnimationFrame garbage collection

百般思念 提交于 2019-12-28 05:09:29
问题 I'm profiling the following code's memory usage using the Timeline in Chrome Dev Tools v27. <!DOCTYPE html> <html> <head> <meta http-equiv='content-type' content='text/html; charset=UTF-8' /> <title>RAF</title> </head> <body> <script type='text/javascript' charset='utf-8'> var frame = function() { window.webkitRequestAnimationFrame(frame); }; window.webkitRequestAnimationFrame(frame); </script> </body> </html> Notice it's simple. But eventually I see the a tooth pattern appear that indicates

SQL Server - Does column order matter?

我的未来我决定 提交于 2019-12-28 04:22:07
问题 In terms of performance and optimizations: When constructing a table in SQL Server, does it matter what order I put the columns in? Does it matter if my primary key is the first column? When constructing a multi-field index, does it matter if the columns are adjacent? Using ALTER TABLE syntax, is it possible to specify in what position I want to add a column? If not, how can I move a column to a difference position? 回答1: In SQL Server 2005, placement of nullable variable length columns has a

i++ less efficient than ++i, how to show this?

妖精的绣舞 提交于 2019-12-28 04:13:33
问题 I am trying to show by example that the prefix increment is more efficient than the postfix increment. In theory this makes sense: i++ needs to be able to return the unincremented original value and therefore store it, whereas ++i can return the incremented value without storing the previous value. But is there a good example to show this in practice? I tried the following code: int array[100]; int main() { for(int i = 0; i < sizeof(array)/sizeof(*array); i++) array[i] = 1; } I compiled it