optimization

Why is tailcall optimization not performed for types of class MEMORY?

南笙酒味 提交于 2021-02-07 05:20:24
问题 I'm trying to understand the implication of System V AMD64 - ABI for returning by value from a function. For the following data type struct Vec3{ double x, y, z; }; the type Vec3 is of class MEMORY and thus the following is specified by the ABI concerning "Returning of Values": If the type has class MEMORY, then the caller provides space for the return value and passes the address of this storage in %rdi as if it were the first argument to the function. In effect, this address becomes a

Optimal shift scheduling algorithm

China☆狼群 提交于 2021-02-07 02:50:55
问题 I have been trying for some time solve a scheduling problem for a pool that I used to work at. This problem is as follows... There are X many lifeguards that work at the pool, and each has a specific number of hours they would like to work. We hope to keep the average number of hours away from each lifeguards desired number of hours as low as possible, and as fair as possible for all. Each lifeguard is also a college student, and thus will have a different schedule of availability. Each week

Persistent in-memory Python object for nginx/uwsgi server

微笑、不失礼 提交于 2021-02-07 02:44:29
问题 I doubt this is even possible, but here is the problem and proposed solution (the feasibility of the proposed solution is the object of this question): I have some "global data" that needs to be available for all requests. I'm persisting this data to Riak and using Redis as a caching layer for access speed (for now...). The data is split into about 30 logical chunks, each about 8 KB. Each request is required to read 4 of these 8KB chunks, resulting in 32KB of data read in from Redis or Riak.

Using type hints to translate Python to Cython

痴心易碎 提交于 2021-02-06 10:00:27
问题 Type Hints now are available in Python 3.5 version. In the specification (PEP 484) the goals (and the non-goals) are exposed clearly: Rationale and Goals This PEP aims to provide a standard syntax for type annotations, opening up Python code to easier static analysis and refactoring, potential runtime type checking, and (perhaps, in some contexts) code generation utilizing type information. [...] Of these goals, static analysis is the most important. Non-goals Using type hints for performance

Project Euler #5(Smallest positive number divisible by all numbers from 1 to 20): Ways to Optimize? ~Java

百般思念 提交于 2021-02-05 20:38:08
问题 Problem 5: 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20? I have solved the problem 5 of Project Euler Here is the Java code: static long FindLcm(long a,long b) { long lcm,hcf = 0; long i=1; long ger=a>b?a:b; while(i<ger) { if((a%i==0) && (b%i==0)) hcf=i; i++; } lcm=(a*b)/hcf; return lcm; } static void FindMultiple() { long lcm=1; for

How to load (or map) file part maximum size, but fit in RAM on Windows?

冷暖自知 提交于 2021-02-05 12:21:02
问题 There is big file. I need fast sort it. I going to process the file by part, that fit in RAM, to avoid/degrees using page file (next step: merge parts). How to use max RAM? My solution: use WinApi file memory mapping, but I don't knew how to get part of file maximum size, but fit RAM (how to determine size)? 回答1: You can VirtualLock the pages you want to process. It locks in physical memory the size you need (if there is enough) swapping others to the paging file. You can use the

Optimal path through a matrix with multiple costs to consider

蓝咒 提交于 2021-02-05 07:55:09
问题 For example given the below matrix: [[[0, 8], [0, 3], [0, 8]], [[8, 0], [3, 0], [0, 5]], [[0, 1], [0, 6], [0, 0]]] where for each tuple the first number is food and the second number is water. I need to get from the bottom right to the top left and I can only move up or left. I need to gather as much food and water as possible so I can survive as long as possible. For each day I want to survive I need 1 food and 1 water so if I could choose between a path that would result in (7,4) and one

Is it possible to modify or remove an anonymous type from an object in c#?

百般思念 提交于 2021-02-04 21:10:37
问题 I have a piece of code like below: var selected = “A”; bool isSelected = selected == "A" || selected == "C"; var codeLists = new { displayProperty1 = isSelected ? "property1" : null, displayProperty2 = isSelected ? "property2" : null, displayProperty3 = selected == "C" ? "property3" : null }; So, my goal is to eliminate a property if it does not satisfy a condition. In the above code, selected is "A" . So, displayProperty3 would have a value of null . But I want to eliminate displayProperty3

How to efficiently count the highest power of 2 that is less than or equal to a given number? [duplicate]

て烟熏妆下的殇ゞ 提交于 2021-02-04 14:37:07
问题 This question already has answers here : Rounding up to next power of 2 (26 answers) What is the fastest/most efficient way to find the highest set bit (msb) in an integer in C? (28 answers) Closed 3 years ago . I came up with three solutions so far: The extremely inefficient standard library pow and log2 functions: int_fast16_t powlog(uint_fast16_t n) { return static_cast<uint_fast16_t>(pow(2, floor(log2(n)))); } Far more efficient counting subsequent powers of 2 until I reach a greater

Sum of primes below 2,000,000 in python

跟風遠走 提交于 2021-02-04 14:08:41
问题 I am attempting problem 10 of Project Euler, which is the summation of all primes below 2,000,000. I have tried implementing the Sieve of Erasthotenes using Python, and the code I wrote works perfectly for numbers below 10,000. However, when I attempt to find the summation of primes for bigger numbers, the code takes too long to run (finding the sum of primes up to 100,000 took 315 seconds). The algorithm clearly needs optimization. Yes, I have looked at other posts on this website, like