Splitstr speedup?

Discuss any general programming issues here
Post Reply
User avatar
Tarzin
Posts: 68
Joined: Mon Feb 15, 2010 11:46 am
Location: Dunkerque / FRANCE
Contact:

Splitstr speedup?

Post by Tarzin » Sat Jun 12, 2010 8:01 am

Hello,

This was my original question asked on the mailing list

---
Hello,

I'm currently trying to read datas from an ASCII file.
No problem to open the file but I' don't know how can I read datas and
insert them in many tables

This is an example from my file

1869 - History Experience Part I (AGA);Flair; Max Design;Wilfried Reiter,
Albert Lasser & Martin Lasser;Hannes Seifert;Martin Lasser & Wilfried
Reiter;Straté gie-Commerce; 1 à 4;1993;AGA;no; no;no;4;Anglais; Flair;no; no;

Datas are separated with ";"
Full ASCII file contains 1824 lines

Structure is in fact
Game's
Name;Publisher; Developer; Coder;Musican; Artist;Type; Players;Config; CPUBlit;IBlit; 8Mo;Discs; Langage;Publisher;
Logo;Youtube; WHD;Code; Year;Exclusion Tag

But how can I read datas and assign first data to Game, second data to
publisher, ect...?
I've started ro read documentation for seek() command but don't
understand how to use it in my case.
---

@Rev. Bloedel said to me "Check out the documentation for SplitStr()."

I've watched documentation and code this piece of software

Dim chainejx$[5000]
Dimstr titre[5000], editeur[5000], dev[5000], codeur[5000], gfx[5000], mus[5000], genre[5000]
Dimstr joueur[5000], config[5000], cpu[5000], iblit[5000], hmo[5000], lang[5000], logoed[5000], youtube[5000], WHD[5000], code[5000]
Dim annee[5000], nbdisk[5000], chainelng$[1000]

OpenFile(1,fichier$, #MODE_READ)
info=GetFileAttributes(fichier$)
taille=(FileLength(1))

; Reads numer of games and lines
nbdata=Nil
donnees$=ReadString(1, FileLength(1))
ligne, nbdata=SplitStr(donnees$, "\n")

For Local compt=1 To nbtitres-1
chainejx$[compt]=SplitStr(donnees$, "\n")

For Local compt1=1 To nbtitres-1
jeux = SplitStr(ligne[compt1], ";")
titre[compt1]=jeux[0]
editeur[compt1]=jeux[1]
dev[compt1]=jeux[2]
codeur[compt1]=jeux[3]
mus[compt1]=jeux[4]
gfx[compt1]=jeux[5]
genre[compt1]=jeux[6]
joueur[compt1]=jeux[7]
annee[compt1]=jeux[8]
config[compt1]=jeux[9]
cpu[compt1]=jeux[10]
iblit[compt1]=jeux[11]
hmo[compt1]=jeux[12]
nbdisk[compt1]=jeux[13]
lang[compt1]=jeux[14]
logoed[compt1]=jeux[15]
youtube[compt1]=jeux[16]
whd[compt1]=jeux[17]
code[compt1]=jeux[18]
Next
Next

This code works but is VERY slow! I'm working on a file wich contains about 1800 lines to check and split.
Is there any way to speedup this?

Thanks for advance!
A500 / A600 / A1200 / SAM440
WinUAE OS3.9 (AmiKit) / OS4.1FE (FlowerPot)
---
https://twitter.com/TarzinCDK

User avatar
Allanon
Posts: 461
Joined: Sun Feb 14, 2010 7:53 pm
Location: Italy
Contact:

Re: Splitstr speedup?

Post by Allanon » Sat Jun 12, 2010 11:38 am

Hello Tarzin
don't know if my suggestion will speedup things because I've ton tested but you should use in this case tables:

Instead of having:

Code: Select all

name[1000]
surname[1000]
age[1000]
job[1000]
you could use:

Code: Select all

Database = {}
then, for every record you have retrieved and splitted:

Code: Select all

Database[record_number] = { name = splitted_string[1], surname = splitted_string[2], age = splitted_string[3], job = splitted_string[4]
For faster access you can index the table Database with something relevant for you, in this case something like <surname>, so, later, if you are looking for the surname "Winter" you can easily access it with:

Code: Select all

index = "Winter"
Database[index] ; <--- contains your data record
DebugPrint(Database[index].name)
Using string index can help you a lot to find data faster instead of searching trhough the list :)
----------------------------
[Allanon] Fabio Falcucci
AMC - Creative Development // Docs Site // Support Forum
Support me on Patreon for Hollywood libraries!

User avatar
Tarzin
Posts: 68
Joined: Mon Feb 15, 2010 11:46 am
Location: Dunkerque / FRANCE
Contact:

Re: Splitstr speedup?

Post by Tarzin » Tue Jul 20, 2010 11:07 pm

Hello Allanon,

Sorry for this long delay without any answer.
I've started to managed another method. I've created as many files on my hard drive as there're records in my table
Insead of having 1 file with 1724 records, I've created 1724 files of 1 record

File name is "1869 - History Experience Part I (AGA)" and contains followings datas: Flair; Max Design;Wilfried Reiter, Albert Lasser & Martin Lasser;Hannes Seifert;Martin Lasser & Wilfried Reiter;Stratégie-Commerce; 1 à 4;1993;AGA;no; no;no;4;Anglais; Flair;no; no;

Then I run my previous code on one file which contains data for one game. It's not the best solution but it's really quick (even on 68k)

BTW, your solution will help me for another problem, thanks! (I'll also try to send you a sample code for subject with layers and Scuilib ASAP)
A500 / A600 / A1200 / SAM440
WinUAE OS3.9 (AmiKit) / OS4.1FE (FlowerPot)
---
https://twitter.com/TarzinCDK

Post Reply