473,383 Members | 1,846 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,383 software developers and data experts.

2nd Try - Why is my Time algorithm so slow (simpler version)

Hi,

Here is a much simpler version of my time scheduling program. As you can see
in the GV (Global Variable class) I have 2 arrays gaSumWorkDays (already
initialized with the values) and gaSeconds. All I want to do when I run my
CVerifyMissingTime class is to verify whether the sum of the 2 colums of
gaSeconds in gaSumWorkDays is > 0.

I hope that this is more intuitive than the first version.

Here is the code below. I have indeted it to make it clearer.

TIA

Roy



using System;

class cMain

{

public static int Main()

{
int lnTotMissingTime=0;
int t = DateTime.Now.Minute*60+DateTime.Now.Second;

Console.WriteLine("TimeStarted "+t);

lnTotMissingTime=CVerifyMissingTime.VerifyMissingT ime();
Console.WriteLine("Total No of Missing Time {0}
",lnTotMissingTime);

t = DateTime.Now.Minute*60+DateTime.Now.Second;

Console.WriteLine("Time Ended "+t);

Console.ReadLine();

return 0;

}

}

public class GV

{

public const int kNoWeeks=11;

public static int gnSumSeconds = 0;

public static int[] gaWorkDays= new int [7];

public static int[] gaSumWorkDays = new int[61]

{ 0
,1,0,1,0,1,0,1,1,1,1,1,0,1,1,1,0,1,1,0,1,1,0,1,1,1 ,0,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,0,1,1,1,0,1,1,1,1 ,1,0,1,1,1,0,1,1,1,0};

public static int[,] gaSeconds = new int [kNoWeeks+1,3]

{

{ 0, 0, 0},

{ 0, 9, 0},

{ 0, 17, 1},

{ 0, 24, 2},

{ 0, 30, 3},

{ 0, 35, 4},

{ 0, 39, 5},

{ 0, 42, 6},

{ 0, 44, 7},

{ 0, 45, 8},

{0, 0, 9},

{0, 0, 10}};

}

class CVerifyMissingTime

{

public static int VerifyMissingTime() {

int lnSumMissingTime=0;

for (int xxxLoop=1 ; xxxLoop<=10; xxxLoop++) {

lnSumMissingTime=0;

for (int lp1=1 ; lp1<=GV.kNoWeeks-5 ; lp1++) {

for (int lp2=lp1+1 ; lp2<=GV.kNoWeeks-4 ;
lp2++) {

for (int lp3=lp2+1 ;
lp3<=GV.kNoWeeks-3 ; lp3++) {

for (int lp4=lp3+1 ;
lp4<=GV.kNoWeeks-2 ; lp4++) {

for (int lp5=lp4+1 ;
lp5<=GV.kNoWeeks-1 ; lp5++) {

for (int
lp6=lp5+1 ; lp6<=GV.kNoWeeks ; lp6++) {

if
(GV.gaSumWorkDays[GV.gaSeconds[lp1,1]+GV.gaSeconds[lp2,2]]>0) {
lp6=lp5=lp4=100;
continue;

}

if
(GV.gaSumWorkDays[GV.gaSeconds[lp1,1]+GV.gaSeconds[lp2,2]]>0) {
lp6=lp5=100;
continue;

}

if
(GV.gaSumWorkDays[GV.gaSeconds[lp1,1]+GV.gaSeconds[lp3,2]]>0) {
lp6=lp5=100;
continue;

}

if
(GV.gaSumWorkDays[GV.gaSeconds[lp2,1]+GV.gaSeconds[lp3,2]]>0) {
lp6=lp5=100;
continue;

}

if
(GV.gaSumWorkDays[GV.gaSeconds[lp1,1]+GV.gaSeconds[lp2,2]]>0) {
lp6=100;
continue;

}

if
(GV.gaSumWorkDays[GV.gaSeconds[lp1,1]+GV.gaSeconds[lp3,2]]>0) {
lp6=100;
continue;

}

if
(GV.gaSumWorkDays[GV.gaSeconds[lp1,1]+GV.gaSeconds[lp4,2]]>0) {
lp6=100;
continue;

}

if
(GV.gaSumWorkDays[GV.gaSeconds[lp2,1]+GV.gaSeconds[lp3,2]]>0) {
lp6=100;
continue;

}

if
(GV.gaSumWorkDays[GV.gaSeconds[lp2,1]+GV.gaSeconds[lp4,2]]>0) {
lp6=100;
continue;

}

if
(GV.gaSumWorkDays[GV.gaSeconds[lp3,1]+GV.gaSeconds[lp4,2]]>0) {
lp6=100;
continue;

}

if
(GV.gaSumWorkDays[GV.gaSeconds[lp1,1]+GV.gaSeconds[lp2,2]]>0) {
continue;

}

if
(GV.gaSumWorkDays[GV.gaSeconds[lp1,1]+GV.gaSeconds[lp3,2]]>0) {
continue;

}

if
(GV.gaSumWorkDays[GV.gaSeconds[lp1,1]+GV.gaSeconds[lp4,2]]>0) {
continue;

}

if
(GV.gaSumWorkDays[GV.gaSeconds[lp1,1]+GV.gaSeconds[lp5,2]]>0) {
continue;

}

if
(GV.gaSumWorkDays[GV.gaSeconds[lp2,1]+GV.gaSeconds[lp3,2]]>0) {
continue;

}

if
(GV.gaSumWorkDays[GV.gaSeconds[lp2,1]+GV.gaSeconds[lp4,2]]>0) {
continue;

}

if
(GV.gaSumWorkDays[GV.gaSeconds[lp2,1]+GV.gaSeconds[lp5,2]]>0) {
continue;

}

if
(GV.gaSumWorkDays[GV.gaSeconds[lp3,1]+GV.gaSeconds[lp4,2]]>0) {
continue;

}

if
(GV.gaSumWorkDays[GV.gaSeconds[lp3,1]+GV.gaSeconds[lp5,2]]>0) {
continue;

}

if
(GV.gaSumWorkDays[GV.gaSeconds[lp4,1]+GV.gaSeconds[lp5,2]]>0) {
continue;

}

lnSumMissingTime++;

}

}

}

}

}

}

}

Console.WriteLine("Missing Time {0}",lnSumMissingTime);

return lnSumMissingTime;

}

}


Nov 17 '05 #1
1 1286
Roy Gourgi <ro***@videotron.ca> wrote:
Here is a much simpler version of my time scheduling program. As you can see
in the GV (Global Variable class) I have 2 arrays gaSumWorkDays (already
initialized with the values) and gaSeconds. All I want to do when I run my
CVerifyMissingTime class is to verify whether the sum of the 2 colums of
gaSeconds in gaSumWorkDays is > 0.

I hope that this is more intuitive than the first version.


It's slightly simpler, but there's still no indication of what it's
actually meant to do.

I also suspect that there are some bugs in it. For instance, at the
start of the innermost loop (with that many loops, you should really be
considering recursion) you have:

if (GV.gaSumWorkDays[GV.gaSeconds[lp1,1]+GV.gaSeconds[lp2,2]]>0)
{
lp6=lp5=lp4=100;
continue;
}
if (GV.gaSumWorkDays[GV.gaSeconds[lp1,1]+GV.gaSeconds[lp2,2]]>0)
{
lp6=lp5=100;
continue;
}

Now, under what circumstances do you foresee the second "if" condition
being true?

Bugs are hard to find and even harder to fix in code which doesn't have
an obvious meaning.

A first step towards improving the readability here would be to write a
method which took four parameters and returned whether
GV.gaSumWorkDay[GV.gaSeconds[first,second]+GV.gaSeconds[third,fourth]]
was greater than 0 or not. Note that with such a method in place, it
would be *much* easier to then refactor your code to use jagged arrays
rather than rectangular arrays. You could also give the method a name
which indicated what it was actually meant to do...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 17 '05 #2

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

Similar topics

3
by: Edg Bamyasi | last post by:
This Is A Late Cross Post from comp.lang.python. It seems the mistery is deeper then i expected. What is the running time of conactination on character strings. i.e. >> joe="123" >>...
2
by: Yonatan Goraly | last post by:
I am in the process of adding PostgreSQL support for an application, in addition to Oracle and MS SQL. I am using PostgreSQL version 7.3.2, Red Hat 9.0 on Intel Pentium III board. I have a...
38
by: vashwath | last post by:
Might be off topic but I don't know where to post this question.Hope some body clears my doubt. The coding standard of the project which I am working on say's not to use malloc.When I asked my...
113
by: Bonj | last post by:
I was in need of an encryption algorithm to the following requirements: 1) Must be capable of encrypting strings to a byte array, and decyrpting back again to the same string 2) Must have the same...
29
by: Roy Gourgi | last post by:
Hi, I am new to C#. I have the same time scheduling program written in C++ and it is 5 times faster than my version in C#. Why is it so slow as I thought that C# was only a little slower than...
4
by: zing | last post by:
Our company is in the startup phase of a large project involving lots of network traffic. At this point, I'm trying to find out whether TCP will be fast enough for the task. I've read a few...
17
by: Martin Carpella | last post by:
Hello everyone, I experience some strange behaviour of anoynmous delegates which refer to variables outside the scope of the delegate. Please have a look at the following code and output at...
26
by: Lionel B | last post by:
Hi, Anyone know if the Standard has anything to say about the time complexity of size() for std::set? I need to access a set's size (/not/ to know if it is empty!) heavily during an algorithm...
3
by: ahmadcorp.m | last post by:
Hi, Need some ideas for this problem: If you had a file containing boundaries (up to 25 million) and a file containing a list of points P (up to 10 billion). What would be the fastest way to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.