C++ :: Optimizing Timing Functionality?

Jan 18, 2013

I've written a timer function in c/c++, but it still has performance problems. how to optimize this further (atm works with delay to perform timing):

#include "headers/types.h" //Basic types!
#include "headers/timers.h" //Timer support function data!
#include "headers/emu/threads.h" //Thread for timer item!
//Timer step in ms! Originally 100ms
#define TIMER_STEP 10000

[code]....

View 3 Replies


ADVERTISEMENT

C :: Application That Uses Two Different Timing Techniques

Feb 19, 2014

I am looking at a same application in c that uses two different timing techniques. One involves the nanosleep() function which suspends thread for given nanoseconds. The other one uses a combination of gettimeofday() which returns number of microseconds since epoch as a start value. Then it uses var counter of for loop as max value. And it uses ellapsed time for each call of gettimeofday in microseconds in a do while loop to increment diff, until diff is not less than var. Why would someone choose to use this timing techinque be used instead of nanosleep?

Code:
unsigned long getTime() {
struct timeval detail_time;
gettimeofday(&detail_time,NULL);
return (detail_time.tv_usec);

[Code] .....

View 1 Replies View Related

C++ :: Timing Function - Sort Dynamic Array With N Elements

Apr 11, 2014

I'm writing a program that will implement BubbleSort and MergeSort and time them as they sort a dynamic array with N elements. These are the instructions on what my main.cpp file should do.

main.cpp
Include all needed libraries for timing and random number generation while the number of element, N, is less than 100001 repeat the following.

create an array with N (initially 10) random elements
sort the same array with Bubble and Merge sort
time how long it takes each algorithm in microseconds (see example below)
Increase N by a factor of 10 (N *= 10)
Hint: you may want to put your merge sort object on the heap and delete it with every iteration of this loop

And this is what I have so far for my main.cpp

#include <iostream>
#include <sys/time.h>
#include <ctime>
#include <cstdlib>
#include <stack>
#include <iomanip>
#include "BubbleSort.h"
//#include "MergeSort.h"

[Code] .....

One of the errors that I'm running into is that I'm not sure how to correctly call the function I think?

View 3 Replies View Related

C/C++ :: Optimizing Word Generator?

May 25, 2014

Today I came across a problem that I've never had before and haven't thought about. Until now, The optimizing and speed in a program. I've created a small and very easy user input based "Word Generator" just to test and compare other programs.

I have compared my program to another program that works on the same concept that is programmed in C#. What I've heard is that C++ is one of the fastest languages, but still. The C# program I compared to was about 15 seconds faster when both generating 100 000 words.

optimize this program down below and describe what you've done.

#include <iostream>
#include <ctime>
#include <string>
#include "conio.h"

[Code]....

View 9 Replies View Related

C/C++ :: Optimizing Equation For Cases Of 0

Feb 19, 2015

I'm writing an algorithm on a microcontroller in C.

One of the iterations that takes a long time involves the following equation, summing the product of pairs of variables:

signed char VarA;
signed char VarA;
signed long VarA;
Total+=VarA*VarB;

The vast majority of cases, at least one of the variables VarA and VarB will be 0, so nothing will be added to Total.

Is there a way to check for this condition which might give me a performance increase over doing a lot of multiplying-by-zeros?

View 6 Replies View Related

C++ :: JPEGs Recovery From Forensic Image - Optimizing Code

Jan 21, 2013

I'm taking a CS course and we've been tasked with creating a program that recovers jpegs from a formatted CF card which uses the FAT file system with a block size of 512 bytes, the jpegs in the card are block aligned which means that the beginning of a jpeg marks the end of the former.

I've wrote the program and it works nicely and recovers the 51 jpegs in the CF card (actually just an image of some 4-5 megabytes of the actual card which can be downloaded here) but I'm looking for ways to optimize/improve my code so I need a second look from experienced programmers.

Here's my code:

Code:
/*
* filename : recover.c
* description : Recovers jpegs from a forensic image
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#define BLOCK 512 // fat file system block size
int main(void) {
// open CF card image

[Code] .....

My questions are:
1) What are the possible optimizations that can make my code faster/better/more concise?
2) I'm not handling slack space, since trailing zeros at the end of a jpeg won't affect rendering it (we were told it won't contain any garbage values)... how may I approach the problem?
3) Can I enhance my if else constructs? or even replace them with something more elegant?

View 14 Replies View Related

C++ :: Functionality Of A Function?

Mar 7, 2015

I have been working with this code sometime, and i have somewhat lost the 'focus'. The problem is, i really can't seem to figure out what the function InsertAsFirstElement does, because there is no point in the code, something will be input "as first element"?

Code:
#include <iostream>
#include <cmath>
using namespace std;
struct node {
string nameOfFood;
int eatCalories;

[code]....

View 14 Replies View Related

C++ :: Derive A Class From Xml Node To Add More Functionality

Dec 10, 2012

I would like to derive a class from pugi::xml_node to add more functionality to the class. I get stuck when I try to append a child because pug::xml_node append_child return pugi::xml_node (not a pointer).

This is what I've tried, but it fails to compile.

Code:
PugiXmlNode PugiXmlNode::appendChild(std::string name)
{
return (PugiXmlNode) (append_child(name.c_str()));
}

Is there any way to do this?

View 2 Replies View Related

Visual C++ :: Dragging And Dropping Functionality In Windows 8 Environment

Jul 14, 2014

i have developed an application in which i have icons in left side pane of application which can be dragged and dropped in client screen. Application is working fine with all the resolution except 1920x1080.

when setting the resolution to 1920x1080 while dragging icons to client area, icon is not attach to mouse pointer. instead there is a gap between the mouse pointer and the icon. i wrote code to identify the screen resolution but it does not seem to recognize 1920x1080 resolution. below code is giving incorrect resolution for 1920x1080 setting.

RECT actualDesktop;
GetClientRect(GetDesktopWindow(),&actualDesktop);

value of 'actualDesktop' variable is {top=0 bottom=783 left=0 right=1536} which is incorrect. according to current resolution size value should be {top=0 bottom=1080 left=0 right=1920}. Due to this, all the icons while dragging are adjusting according to incorrect resolution setting.

how to identify the issue and if there is any limitation with respect to screen resolution in VC++ 6.0 with windows 8 environment.

I am getting same issue when compiling in VS2012 in windows 8. Code does not seem to recognize 1920x1080 resolution setting and downgrading my application look and feel by setting it to lower resolution.

View 1 Replies View Related

C++ :: Imebra Functionality QT Project Gives Malloc - Error For Object

Nov 2, 2012

I'm trying to convert dicom .dcm file to .jpeg using Imebra in C++ app using QT Creator as dev environment.

I've downloaded Imebra and was able to run QT project example for Dicom2Jpeg conversion successfully. But when I tried to copy same code to my C++ app it failed to run with following error msg:

malloc: * error for object xxxxxx: pointer being freed was not allocated * set a breakpoint in malloc_error_break to debug

I have followed steps on adding Imebra files to my project as it was shown on Imebra site. Also used their qt project as example. My main.cpp open dicom file, then loads it to dataset, then calls my dialog window. It crashes on loading dataset.

#include "QApplication.h"
#include "QHBoxLayout.h"
#include "mydialog.h"
#include "iostream.h"
include "library/imebra/include/imebra.h"
int main( int argc, char ** argv ){

[Code] ....

Deeper debugging showed that source of error is in JpegCodec.cpp file readStream() function when checking JpegSignature to see if it's in wrong format with resulting internal PUNTOEXE error "detected a wrong format".

Interesting thing is that while running same test dcm file using given dicom2jpeg example (which has exact same code of opening file and loading it) gives no errors and converts to jpeg successfully. So I know it's not the file issue, but the way imebra code is integrated into my C++ app.

My dev environment: macbook pro with Lion OS, QT Creator, QT project, C++ code, ITK library added, Imebra files are completely integrated as part of the Qt project.

So, my question is how do I work/link/reference/call Imebra functionality in QT project? Am I forgetting to link something, or some object is not instantiated/deleted on time?

View 2 Replies View Related

C# :: Abstract Class Provide Functionality Without Affecting Child Classes?

Mar 6, 2014

The abstract class can provide more functionality without affecting child classes.If we add any method to the interface ,then will it affect all the child classes ?

View 2 Replies View Related

C++ :: Integration With Word - Highlight Text And Offer Find / Replace Functionality

Sep 10, 2013

I'm undertaking a project at the moment which requires me to hook into a custom c++ application from a Java applet via JNI. The c++ application needs to communicate with MS Word and potentially other office programmes in order to highlight text and offer find/replace functionality programatically. The idea is that when the applet is launched, it will communicate with the C++ methods to hook into an open MS Word document and highlight all words that start with the letter 't' for example.

I'm concentrating on the C++ side of things first . Even some basic access to an open word document would give me a great start!

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved