Questions tagged [processing-efficiency]

622 questions
434
votes
6 answers

Why is (a*b != 0) faster than (a != 0 && b != 0) in Java?

I'm writing some code in Java where, at some point, the flow of the program is determined by whether two int variables, "a" and "b", are non-zero (note: a and b are never negative, and never within integer overflow range). I can evaluate it with if…
379
votes
14 answers

What are the benefits to marking a field as `readonly` in C#?

What are the benefits of having a member variable declared as read only? Is it just protecting against someone changing its value during the lifecycle of the class or does using this keyword result in any speed or efficiency improvements?
leora
  • 188,729
  • 360
  • 878
  • 1,366
73
votes
7 answers

In Java, can & be faster than &&?

In this code: if (value >= x && value <= y) { when value >= x and value <= y are as likely true as false with no particular pattern, would using the & operator be faster than using &&? Specifically, I am thinking about how && lazily evaluates the…
71
votes
2 answers

Why does concatenation of DataFrames get exponentially slower?

I have a function which processes a DataFrame, largely to process data into buckets create a binary matrix of features in a particular column using pd.get_dummies(df[col]). To avoid processing all of my data using this function at once (which goes…
jfive
  • 1,291
  • 3
  • 14
  • 21
40
votes
2 answers

How do I find out what parts of my code are inefficient in Python

On a previous question I was asking about multiprocessing, using multiple cores to make a program run faster, and someone told me this: More often than not, you can get a 100x+ optimization with better code compared to a 4x improvement and…
Rlz
  • 1,649
  • 2
  • 13
  • 36
39
votes
6 answers

Database efficiency - table per user vs. table of users

For a website having users. Each user having the ability to create any amount of, we'll call it "posts": Efficiency-wise - is it better to create one table for all of the posts, saving the user-id of the user which created the post, for each post -…
Yuval A.
  • 5,849
  • 11
  • 51
  • 63
35
votes
20 answers

find pair of numbers in array that add to given sum

Question: Given an unsorted array of positive integers, is it possible to find a pair of integers from that array that sum up to a given sum? Constraints: This should be done in O(n) and in-place (without any external storage like arrays,…
noMAD
  • 7,744
  • 19
  • 56
  • 94
34
votes
5 answers

Efficient integer floor function in C++

I want to define an efficient integer floor function, i.e. a conversion from float or double that performs truncation towards minus infinity. We can assume that the values are such that no integer overflow occurs. So far I have a few…
user1196549
32
votes
4 answers

The most reliable and efficient udp packet size?

Would sending lots a small packets by UDP take more resources (cpu, compression by zlib, etc...). I read here that sending one big packet of ~65kBYTEs by UDP would probably fail so I'm thought that sending lots of smaller packets would succeed more…
pandoragami
  • 5,387
  • 15
  • 68
  • 116
30
votes
2 answers

Cost of push vs. mov (stack vs. near memory), and the overhead of function calls

Question: Is accessing the stack the same speed as accessing memory? For example, I could choose to do some work within the stack, or I could do work directly with a labelled location in memory. So, specifically: is push ax the same speed as mov…
Assad Ebrahim
  • 6,234
  • 8
  • 42
  • 68
25
votes
2 answers

write png quickly

Summary I want to write a .png file as quickly as possible, without a concern for compression. That is, I don't care much about the file size, but I do care that the write happens as quickly as possible. Motivation I am making a web-based map…
M Katz
  • 5,098
  • 3
  • 44
  • 66
25
votes
1 answer

Laravel eager loading vs explicit join

This might sound like an obvious question but I just want to get some reassurance. Using Laravel's eager loading functionality, from what I understand it will create two queries to return a whole list of related results (say if you're working with…
coleman-benjamin
  • 921
  • 1
  • 15
  • 29
24
votes
5 answers

Performance of LIKE queries on multmillion row tables, MySQL

From anybody with real experience, how do LIKE queries perform in MySQL on multi-million row tables, in terms of speed and efficiency, if the field has a plain INDEX? Is there a better alternative (that doesn't filter results out, like the FULLTEXT…
roozbubu
  • 1,106
  • 4
  • 14
  • 30
23
votes
3 answers

Technique to remove common words(and their plural versions) from a string

I am attempting to find tags(keywords) for a recipe by parsing a long string of text. The text contains the recipe ingredients, directions and a short blurb. What do you think would be the most efficient way to remove common words from the tag…
sazr
  • 24,984
  • 66
  • 194
  • 362
16
votes
4 answers

SQL Wildcard Search - Efficiency?

There has been a debate at work recently at the most efficient way to search a MS SQL database using LIKE and wildcards. We are comparing using %abc%, %abc, and abc%. One person has said that you should always have the wildcard at the end of the…
1
2 3
41 42