efficiency

What's the most efficient way to make bitwise operations in a C array

I have a C array like: char byte_array[10]; And another one that acts as a mask: char byte_mask[10]; I would like to do get another array that is the result from the first one plus the second one using a bitwise operation, on each byte. What's the most efficient way to do this? thanks for your answers. ...

How could I implement logical implication with bitwise or other efficient code in C?

I want to implement a logical operation that works as efficient as possible. I need this truth table: p q p → q T T T T F F F T T F F T This, according to wikipedia is called "logical implication" I've been long trying to figure out how to make this with bitwise operations in C without using cond...

Memory efficiency: One large dictionary or a dictionary of smaller dictionaries?

I'm writing an application in Python (2.6) that requires me to use a dictionary as a data store. I am curious as to whether or not it is more memory efficient to have one large dictionary, or to break that down into many (much) smaller dictionaries, then have an "index" dictionary that contains a reference to all the smaller dictionarie...

Best way to do binary arithmetic in C?

I am learning C and am trying to write a program that will take 2 value from a user and will check if these strings are binary values (composed of the characters 1 or 0 is how I approached it) before attempting to, according to user selection: Add the two values, Subtract input 2 from input 1, or Multiply the two values. I can implem...

Perl: Programming Efficiency when computing correlation coefficients for a large set of data

EDIT: Link should work now, sorry for the trouble I have a text file that looks like this: Name, Test 1, Test 2, Test 3, Test 4, Test 5 Bob, 86, 83, 86, 80, 23 Alice, 38, 90, 100, 53, 32 Jill, 49, 53, 63, 43, 23. I am writing a program that given this text file, it will generate a Pearson's correlation coefficient table that looks li...

Declaring Multiple Variables in JavaScript

Hello, In JavaScript, it is possible to declare multiple variables like this: var variable1 = "Hello World!"; var variable2 = "Testing..."; var variable3 = 42; ...or like this: var variable1 = "Hello World!", variable2 = "Testing...", variable3 = 42; Is one method better/faster than the other? Thanks, Steve ...

Building a "crosstab" or "pivot" table from an array in php

I have an array of objects defined similarly to the below: $scores = array(); // Bob round 1 $s = new RoundScore(); $s->Round_Name = 'Round 1'; $s->Player_Name = 'Bob'; $s->Score = 10; $scores[0] = $s; // Bob round 2 $s = new RoundScore(); $s->Round_Name = 'Round 2'; $s->Player_Name = 'Bob'; $s->Score = 7; $scores[1] = $s; // Jack ro...

Efficient in-line search and replace for large file

Hi. There are some standard tools to do this, but I need a simple GUI to assist some users (on windows). They will get an open file dialog and pick the file to process. The file will be an XML file. The file will contain (within the first few lines) a text string that needs to be deleted or replaced with whitespace (doesn't matter which...

Log4J - Speed of resolving class/method/line references

Does log4J still gather the class, method and line numbers by generating exceptions and inspecting the stack trace? Or has Java been optimized since Sun included their own logging framework. If not, why has there not been any optimizations made since. What is the main challenges in obtaining class, method and line numbers quickly and ...

Implementing a matrix, which is more efficient - using an Array of Arrays (2D) or a 1D array?

Hey everyone, When implementing a Matrix construct using arrays, which would be more efficient? Using a 1D array, or an array of arrays (2D)? I would think a 2D is more efficient as you already have the X and Y coordinates of an element, where in a 1D implementation you have to calculate the index. Any thoughts? Thank you Edit: it ...

A good method for conflating queue entries

I have a pool of threads which are fed tasks from a queue. Generally, a small number of threads are able to keep the queue empty. Occasionally, a particularly large burst of events will keep the queue size above zero for some time, but not for long. My concern is regarding events that are duplicates or carry data that obsoletes previous...

How do you find the best way to focus on a coding project/task?

In short, when you have planned or have thought about an idea to create - what do you use to help keep you on task, or to make sure you stay programming without (negative) distraction? I've found that reading books and being around like minded people does help with motivation, although when it comes time to being by yourself typing away...

freelancer's ready-to-go code.

It's been a time since I've been on the freelance market, now I'd like to dive into that once again and I feel the best way to save private time and effort is to prepare myself some ready-to-go solutions for the most common needs. My list includes (some of them I have already done from past project, some will just write or adapt from var...

Do valid web pages load faster?

I am a fan of valid web pages and always spend time passing new sites through the W3C validator. When trying to make a case for why companies should validate web pages I quickly thought of accesibility and the future-proofing of the web site on more primitive devices such as phones, fridges, watches, the next-big-thing etc. However I t...

Best way to store a sparse matrix in .NET

We have an application that stores a sparse matrix. This matrix has entries that mostly exist around the main diagonal of the matrix. I was wondering if there were any efficient algorithms (or existing libraries) that can efficiently handle sparse matrices of this kind? Preferably, this would be a generic implementation where each mat...

Efficient way of storing Huffman tree

I am writing a Huffman encoding/decoding tool and am looking for an efficient way to store the Huffman tree that is created to store inside of the output file. Currently there are two different versions I am implementing. This one reads the entire file into memory character by character and builds a frequency table for the whole docum...

Cache efficient code

This could sound a subjective question, but what i am looking for is specific instances which you would have encountered related to this. How to make a code, cache effective-cache friendly? (More cache hits, as less cahce misses as possible). from both perspectives, data cache & program cache(instruction cache). i.e. What all things in...

Reporting Queries: Best Way to Join Multiple Fact Tables?

I'm working on a reporting system that allows the user to arbitrarily query a set of fact tables, constraining on multiple dimension tables for each fact table. I've written a query-builder class that automatically assembles all the correct joins and subqueries based on the constraint parameters, and everything works as designed. But, I...

Efficient SQL Query

Note: These are not homework problems. I am studying dbms on my own, hence these homework-like questions. Two tables : Teachers (teacher_id, teacher_name) Courses (teacher_id,course_id, course_name) In order to select teacher names who are not teaching any courses, there are two queries I can think of : mysql> explain select teach...

Is there a better way in C# to round a DateTime to the nearest 5 seconds?

Hi all, I want to round a DateTime to the nearest 5 seconds. This is the way I'm currently doing it but I was wondering if there was a better or more concise way? DateTime now = DateTime.Now; int second = 0; // round to nearest 5 second mark if (now.Second % 5 > 2.5) { // round up second = now.Second + (5 - (now.Second % 5));...