开发者

Need help with multiple loop efficiency

I am writing a routine which works out the accruals of certain benefits to people within a given month and the dates of payment of those accruals.

There are a few things to loop through and I am wondering how to increase the efficiency of the loop structure (or use alternatives).

When I take a certain benefit, I have to work out whether it is simple or complex. Simple means you get paid x every 14 days. Complex means a few things:

  • that you get paid every x days, x can be defined.
  • the amount depends on whether you have worked each day (so I need to look up and see if this person works a weekend, when they are taking holidays)
  • the benefit can be suspended over certain periods of the year (e.g. school term holidays, only between 1 April and 23 August)

I am looking for some patterns somewhere, whether they be in a book or on a website. I am not asking anyone to design it for me.

I have tried some shortcuts with a few things:

  1. I have taken holidays and serialised the dates into a string, and then just use a standard InString function to check if the data is in there
  2. Creating arrays I can check (in some cases, the InString seems to work faster), rather than looping through a recordset
  3. Using simple SQL statements (SELECT ixHoliday from tblHoliday Where tblHoliday.dtHoliday = dtInspected)

However, the table I am using creates individual holiday days (it reads off another system). This helps with this year's booked holidays but does not help with Easter etc (unless i eneter them in - and I have the algorithm for that). The problem comes in years to come, where I make simplifying assumptions.

This is used to prepare 5 year forecasts开发者_高级运维.

I am taking a profiler to the design shortly, but was wondering about any resource about structuring these kind of patterns.


I can't comment on the rest of your algorithm, as it sounds highly domain-specific, but surely this

I have taken holidays and serialised the dates into a string, and then just use a standard InString function to check if the data is in there

is not the fastest/easiest/most efficient way to test if a collection contains a Date of a given value.

Regardless of what language you are using (and you did not specify), any modern language/library (certainly C# and Java) have container objects and structures which offer operations to test if an object is contained in some list that doesn't devolve into serialization and String parsing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜