optimization

Find the Minimum Positive Value

五迷三道 提交于 2020-01-03 08:45:53
问题 What's the best algorithm to find the smallest non zero positive value from a fixed number (in this case 3) of values or return 0 if there are no positive questions? My naive approach is below (in Delphi, but feel free to use whatever you like), but I think there's a more elegant way. value1Temp := MaxInt; value2Temp := MaxInt; value3Temp := MaxInt; if ( value1T > 0) then value1Temp := value1; if ( value2 > 0) then value2Temp := value2; if ( value3 > 0) then value3Temp := value3; Result :=

Is there a way cleanly use hidden classes in javascript when you dont know what the properties will be?

拜拜、爱过 提交于 2020-01-03 07:32:12
问题 I have a (GIS) project which displays large amounts of customer data (Thousands of records) to clients. Where nescessary/possible/required, we use server side pagination/filtering/data manipulation but there are cases where it is most efficient to send the data in JSON format to the client and let their browser do the filtering. The amount of data is large, so we format it to save on bandwidth and parsing time - instead of individual objects, we send a structure that includes the attribute

Getting GHC to produce “Add With Carry (ADC)” instructions

感情迁移 提交于 2020-01-03 06:48:10
问题 Here is code that adds two triples of unboxed Words representing a 192 bit number into a new triple of unboxed Words, and also returns any overflow: {-# LANGUAGE MagicHash #-} {-# LANGUAGE UnboxedTuples #-} import GHC.Prim(plusWord2#, Word#, or#) longAdd :: (# Word#, Word#, Word# #) -> (# Word#, Word#, Word# #) -> (# Word#, (# Word#, Word#, Word# #) #) longAdd (# xl, xm, xh #) (# yl, ym, yh #) = let plusWord3 x y c = let (# c1, r1 #) = plusWord2# x y (# c2, r2 #) = plusWord2# r1 c in (#

Performance difference of signed and unsigned integers of non-native length

一笑奈何 提交于 2020-01-03 06:04:40
问题 There is this talk, CppCon 2016: Chandler Carruth “Garbage In, Garbage Out: Arguing about Undefined Behavior...", where Mr. Carruth shows an example from the bzip code. They have used uint32_t i1 as an index. On a 64-bit system the array access block[i1] will then do *(block + i1) . The issue is that block is a 64-bit pointer whereas i1 is a 32-bit number. The addition might overflow and since unsigned integers have defined overflow behavior the compiler needs to add extra instructions to

Performance difference of signed and unsigned integers of non-native length

好久不见. 提交于 2020-01-03 06:04:10
问题 There is this talk, CppCon 2016: Chandler Carruth “Garbage In, Garbage Out: Arguing about Undefined Behavior...", where Mr. Carruth shows an example from the bzip code. They have used uint32_t i1 as an index. On a 64-bit system the array access block[i1] will then do *(block + i1) . The issue is that block is a 64-bit pointer whereas i1 is a 32-bit number. The addition might overflow and since unsigned integers have defined overflow behavior the compiler needs to add extra instructions to

Alternative when IN clause is inputed A LOT of values (postgreSQL)

最后都变了- 提交于 2020-01-03 05:51:08
问题 I'm using the IN clause to retrieve places that contains certain tags. For that I simply use select .. FROM table WHERE tags IN (...) For now the number of tags I provide in the IN clause is around 500) but soon (in the near future) number tags will probably jump off to easily over 5000 (maybe even more) I would guess there is some kind of limition in both the size of the query AND in the number values in the IN clause (bonus question for curiosity what is this value?) So my question is what

Performance of Concurrent Program Degrading with Increase in Threads?

て烟熏妆下的殇ゞ 提交于 2020-01-03 05:37:11
问题 I have been trying to implement the below code on quad core computer and average running times with No of threads in the Executor service over 100 iterations is as follows 1 thread = 78404.95 2 threads = 174995.14 4 thread = 144230.23 But according to what I have studied 2*(no of cores) of threads should give optimal result for the program which is clearly not the case in my program which bizarrely gives best time for single thread. Code : import java.util.Collections; import java.util.Random

Avoiding 'sort order by' in query plan

Deadly 提交于 2020-01-03 05:32:18
问题 I have a table like this: create table A ( fieldA numeric, fieldB varchar(255), fieldC varchar(255), ... fields ... constraints ... ); And I have unique B-tree index on fieldB . So, when I execute query like this: select /*+ index(a)*/ * from A a where fieldB > 'LOW' and fieldB < 'HIGH' order by fieldB I expect to see query plan with index range scan and without sort order by clause (or any other type of sort), because of existing index. In fact, I have sort order by in query plan explain

Mixed integer programming: variable assignment per condition (if then else)

不想你离开。 提交于 2020-01-03 05:20:10
问题 I am relatively new to (mixed) integer programming and got stuck with the formulation of a constraint. In my simplified model I have one Parameter and two Variables that are positive Reals having the value 321 as upper bound. The logic I want to express is here: if Parameter > Variable1: Variable2 = Variable1 else: Variable2 = Parameter **edit** (while Variable1 is always >= Variable2) Is it actually possible to describe this using linear in(equalities)? If it helps: For the implementation I

Android OpenGL 2.0 Sprite Optimization

拟墨画扇 提交于 2020-01-03 04:50:27
问题 Hej, I'm creating simple game for Android in OpenGL ES 2.0. The game will contain few types of different sprites, but these will occur more than once. For now let's say I have 1 object (sprite). So far I've implemented VBO and Index buffering, so an object as whole is stored on GPU, as I understand. What I would like to do now is to draw this object multiple times, only thing differing it's position. As for now, this is implemented as follows: glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer