Recent

Author Topic: Fastest way to copy a record or an array of record  (Read 5081 times)

Zomis

  • Jr. Member
  • **
  • Posts: 95
Fastest way to copy a record or an array of record
« on: February 08, 2007, 05:16:11 pm »
I was wondering which the fastest way is to copy a record or an array of record?
Is it onevar:=secondvar that is the fastest, or is it faster to use some kind of CopyMemory function if it's avalible?

I need to copy one record of 33819 bytes
And one static array of 5672823 bytes (871 * 6513 bytes)
This copying will be done many many times, since it's for indexing game levels into a database. For each new item, the old data must be reset to default values.

Manlio

  • Full Member
  • ***
  • Posts: 162
  • Pascal dev
Re: Fastest way to copy a record or an array of record
« Reply #1 on: May 30, 2021, 11:18:26 am »
I don't know why no one ever replied here, but I think it's an interesting subject in many situations, and therefore I'll try to answer it.

And my answer to the question is: MEASURE it.

Code: [Select]

// measure method #1
T := GetTickCount64;
for i := 1 to 1000000 do
  record1 := record2;
T1 := GetTickCount64 - T;

// measure method #2
T := GetTickCount64;
for i := 1 to 1000000 do
  Move(record1, record2, SizeOf(TRecord));
T2 := GetTickCount64 - T;

// and so on... run different methods and compare the time it takes

I have done similar things in the past and I often found surprising results, e.g. sometimes assigning 0 to each field manually was faster than using FillChar, things like that.

Bottom line, don't rely on guesses or reasoning when you can easily measure.

manlio mazzon gmail

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: Fastest way to copy a record or an array of record
« Reply #2 on: May 30, 2021, 11:26:50 am »
I don't know why no one ever replied here, but I think it's an interesting subject in many situations, and therefore I'll try to answer it.

Because the question is 13 years old, the poster left the forum not long after posting it, and the convention is that old threads are not resurrected without /very/ good reason.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018