473,440 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,440 software developers and data experts.

Speed problem

Hi,

I have a small problem here. I put in a paper today, which was basically a
programming project for a
sudoku solver.

I got the programm working without a problem, but somehow the algorithm
isn't running as fast as I thought it would.
I talked to some of my colleagues and they basically told me that their
algorithms were mostly not more complex than
mine. Mostly even more simply, yet their programs solved a certain set of
100 sudokus in under 2 minutes, where
mine needed 15 minutes.
I activated all optimization options, used /O2 in Visual C++ but that only
gave me like 2 seconds less computing time.

I went throught the algorithm over and over and I am sure that it does work
correctly, I put it on 20000 different sudokus
in a file I found and it solved them all in a time of about 1.6 seconds per
sudoku, which is simply not fast enough.

Problem is I don't have any idea why it is so slow, while other programs
which do basically do exactly the same are
doing it so much faster.

Don't missunderstand me, I don't want to get you to help me get more points,
I put the project in already anyway.
It's just that I will only get a score for the project, but no explanation
on why it was so slow and since I am simply
curious on what I did wrong I would appreciate if anyone her could give me a
hint or two.
I will upload the code under the following link so I don't have to put it in
here, since even just writing the functions which
actually do compute the algorithm would still be too much for a post here.
I don't want to short it down though, since I want to show you the actual
code as is so you can find anything
that might be slowing it down too much.
I know looking through all that code is a little work, but I would really
appreciate any help.
Again, my problem is not correctness or how to do it, but how to do it
faster, a lot faster.

Thanks in advance... here's the link:

http://www.wcrevival.de/joker/CSudokuRiddle_cpp.txt

Jul 20 '06 #1
7 1398
Andreas Schmitt wrote:
I have a small problem here. I put in a paper today, which was
basically a programming project for a
sudoku solver.

I got the programm working without a problem, but somehow the
algorithm isn't running as fast as I thought it would.
[...]

Thanks in advance... here's the link:

http://www.wcrevival.de/joker/CSudokuRiddle_cpp.txt
Functionality is missing there. No 'Init', no c-tor, no d-tor (if
it's needed at all, that is), no 'main'. No source data either.
What should we be looking at? How should we figure out what makes
it slow?

In any case, have you tried using a profiler? You may need to learn
what they are and how to use them.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 20 '06 #2
Functionality is missing there. No 'Init', no c-tor, no d-tor (if
it's needed at all, that is), no 'main'. No source data either.
What should we be looking at? How should we figure out what makes
it slow?
Alright, I uploaded the entire code:

http://www.wcrevival.de/joker/Sudoku_cpp.txt
http://www.wcrevival.de/joker/CSudokuRiddle_cpp.txt
http://www.wcrevival.de/joker/CSudokuRiddle_h.txt
Jul 20 '06 #3

"Andreas Schmitt" <Ke**********@gmx.deschrieb im Newsbeitrag
news:e9*************@news.t-online.com...
>Functionality is missing there. No 'Init', no c-tor, no d-tor (if
it's needed at all, that is), no 'main'. No source data either.
What should we be looking at? How should we figure out what makes
it slow?

Alright, I uploaded the entire code:

http://www.wcrevival.de/joker/Sudoku_cpp.txt
http://www.wcrevival.de/joker/CSudokuRiddle_cpp.txt
http://www.wcrevival.de/joker/CSudokuRiddle_h.txt

And the source data, in case you need it:

http://www.wcrevival.de/joker/input.txt
Jul 20 '06 #4

Andreas Schmitt wrote:
"Andreas Schmitt" <Ke**********@gmx.deschrieb im Newsbeitrag
news:e9*************@news.t-online.com...
Functionality is missing there. No 'Init', no c-tor, no d-tor (if
it's needed at all, that is), no 'main'. No source data either.
What should we be looking at? How should we figure out what makes
it slow?
Alright, I uploaded the entire code:

http://www.wcrevival.de/joker/Sudoku_cpp.txt
http://www.wcrevival.de/joker/CSudokuRiddle_cpp.txt
http://www.wcrevival.de/joker/CSudokuRiddle_h.txt
And the source data, in case you need it:

http://www.wcrevival.de/joker/input.txt
* Only use all caps for #define macros - don't use them for typedefs,
structs or class names.
* Init() - You should do the initialisation in the constructor so that
it isn't possible to forget to do it.
* Using new is often acceptable, but if you find you're using delete
then think very carefully. Normally you should try to find a smart
pointer that has the right semantics. For many of your uses I think
boost::scoped_ptr should be fine. Better yet get rid of the pointers
all together.
* Don't use hungarian notation - it's ugly and doesn't really buy you
anything.

I can't really tell how it is solving the puzzles, but it looks like
you're doing a lot of manipulation building and rebuilding data
structures. I would guess that this is a likely place to look for speed
improvements.

You don't seem to be using iterators or any of the algorithms from the
standard library. It may be that restructuring in terms of those would
also help.

You really need a profiler though to get anywhere properly - everything
else is just guess work.

K

Jul 20 '06 #5
typedef std::vector<std::vector<ENTRY>ENTRIES;

won't compile. Needs a space between the two symbols. And
vector<vector< is not usually a good idea anyway although I haven't
looked to see what it is used for here.

std::list is rarely correct to use either. For a small collection of
numbers, if you want an ordered list then use vector<intor even
std::string if all the ints will fit into char, or std::wstring if they
don't but fit into wchar_t. If you don't need ordering then std::bitset
if you know the size you need, vector<boolacts like bitset but is
resizable and vector<intis an alternative but unlike the above
vector<inthere you size it to the number of possibly values you are
looking up and have a 0 or 1 in each slot (but unlike vector<boolyou
can use it with algorithms safely)

Now I mention algorithms - they are obviously key to what you are
doing. Check the complexity of them.

Jul 20 '06 #6
typedef std::vector<std::vector<ENTRY>ENTRIES;
>
won't compile. Needs a space between the two symbols.
Uh? Compiles without problems on my Visual C++ 2005, never read
anywhere that a space is needed there either. Is that fixed in the C++
Standard?
Never heard of that necessity
Jul 20 '06 #7
Andreas Schmitt wrote:
>typedef std::vector<std::vector<ENTRY>ENTRIES;

won't compile. Needs a space between the two symbols.

Uh? Compiles without problems on my Visual C++ 2005, never read
anywhere that a space is needed there either. Is that fixed in the C++
Standard?
Never heard of that necessity
It's supposed to be fixed in C++0x, but in C++98 TC1 2.4/3:

"If the input stream has been pared into preprocessing token up to a
given character, the next preprocessing token is hte longest sequence of
characters that could constitute a preprocessing token, even if that
would cause further lexical analysis to fail."

Thus the >would be tokenized as the right shift operator, rather than
two separate tokens. Try compiling with /Za. What you're seeing is a
language extension in VC2005.
Jul 20 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

34
by: Jacek Generowicz | last post by:
I have a program in which I make very good use of a memoizer: def memoize(callable): cache = {} def proxy(*args): try: return cache except KeyError: return cache.setdefault(args,...
52
by: Neuruss | last post by:
It seems there are quite a few projects aimed to improve Python's speed and, therefore, eliminate its main limitation for mainstream acceptance. I just wonder what do you all think? Will Python...
4
by: Lost Bits | last post by:
Hello there C++ pros.. Well, I have recently redesigned an already existing piece of code that someone else designed - its just a search algorithm they developed, and has to perfomr millions of...
60
by: Neil | last post by:
I have a situation with an ODBC linked view in an Access 2000 MDB with a SQL 7 back end. The view is scrolling very slowly. However, if I open the view in an ADP file, it scrolls quickly. I...
2
by: Roy Gourgi | last post by:
Hi, My program seems to slow down drastically because as I fill my array and table with many values, the program suffers tremendously. The first thing my program does is to search the jagged...
9
by: burningsunorama | last post by:
Hi guys! This is maybe a too 'academic problem', but I would like to hear your opinions, something like pros and cons for each approach.... ... Recently we've had at work a little talk about the...
2
by: Mike Kober | last post by:
I am having issues with the File Upload control for sending files to the server via HTTP. The speed of the upload is often between 20kbs and 40kbs. If I use the LAN at work to the server, it...
6
by: Jassim Rahma | last post by:
I want to detect the internet speed using C# to show the user on what speed he's connecting to internet?
11
by: kyosohma | last post by:
Hi, We use a script here at work that runs whenever someone logs into their machine that logs various bits of information to a database. One of those bits is the CPU's model and speed. While...
4
by: nestle | last post by:
I have DSL with a download speed of 32MB/s and an upload speed of 8MB/s(according to my ISP), and I am using a router. My upload speed is always between 8MB/s and 9MB/s(which is above the max upload...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.