You are Here: Home >< A-levels

A-Level comp4 coursework help watch

1. Hi so i'm at the testing part of my computing coursework and i'm trying to create a trace table for a particular routine which is a nested for loop linear search, it's basically searching live neighbours but in a 2D array, i was wondering if anyone has any ideas of how i could test this works efficiently

Here's the code:
for Row := YMin to YMax do
begin
for Col := XMin to XMax do
begin
if (Row <> Y) or (Col <> X) then
begin
if CopyArray[Row, Col].IsAlive then
LiveNeighbourCount := LiveNeighbourCount + 1
if LiveNeighbourCount > 3 then begin Result := False

case CurrentlyAlive of
True:
if LiveNeighbourCount < 2 then
Result := False
else if LiveNeighbourCount > 3 then
Result := False
else Result := True
end;
False:
begin if LiveNeighbourCount = 3 then
Result := True
else Result := False

Thanks for any help in advance
2. Before being able to test anything, you must first be able to define the objective of that test. So the question "How do I test that this works efficiently" is meaningless and unanswerable until you can quantify the term "efficiently" - i.e. What are your performance requirements versus what kind of data set? Are there 100 entries, 10,000 or 10,000,000 in the data? Should it run in under 1ms? under 100ms? under 1sec? ... 10 sec? .. 1 hour?

The code you've written looks like Delphi to me, so if you are trying to profile some code, then TStopwatch works like a high-resolution timer which is ideal for analysing the performance characteristics of some code:

Before you jump in and start doing this, the most important question to ask is why you're doing this. Performance, Efficiency and Optimisation are only important in situations where your app exhibits some observable behaviour indicating that "something" might be slow - For example, are you having problems with updates in a UI or experiencing some kind of input lag?

Also remember that just because an app is running slowly doesn't mean that there's an issue with efficiency, - sometimes apps run slowly because there are blocking calls to a "wait", or "sleep" causing the app to appear to do nothing when in fact a thread has just been temporarily suspended, and the solution is to restructure the app to remove those blocking calls, or to dispatch them out to a separate thread.

TSR Support Team

We have a brilliant team of more than 60 Support Team members looking after discussions on The Student Room, helping to make it a fun, safe and useful place to hang out.

This forum is supported by:
Updated: March 15, 2018
Today on TSR

Uni league tables

Do they actually matter?

University open days

• Staffordshire University
Everything except: Midwifery, Operating Department Practice, Paramedic Undergraduate
Sun, 21 Oct '18
• University of Exeter
Wed, 24 Oct '18
Wed, 24 Oct '18
Poll

All the essentials

Student life: what to expect

What it's really like going to uni

Essay expert

Learn to write like a pro with our ultimate essay guide.

Create a study plan

Get your head around what you need to do and when with the study planner tool.

Resources by subject

Everything from mind maps to class notes.

Study tips from A* students

Students who got top grades in their A-levels share their secrets