On Mar 29, 4:31 am, hendra kusuma <[email protected]> wrote: > On Tue, Mar 29, 2011 at 7:05 PM, hendra kusuma <[email protected]>wrote: > > > Dear all, > > > Is there a way to convert sequel dataset to 2D array? > > I need all data in my table and save it in 2D array. > > converting it manually by reading each data and save it to array > > result in horibly slow performance, > > 5000 records with 20 field takes 15 sec > > just want to make myself clear > I am developing a business desktop application for my own store here > I use gtk and sequel, and so far I am happy with those lib > but then when i need to display all my product in grid / treeview, i got > stuck > > I have about 1000 record in product table, which has 20 column (sorry, > wrongly type as 5000 up there) > so basically, i need to loop over my data, and assign it to my grid > this line give me 15 sec > > Product.select_all.each do |p| > true > end > > yes, you read correctly. Product is a model class. I don't do anything > there, just loop and return true, and it gives me 15 sec > > While sequel is fantastic and elegant, that kind of performance is > unacceptable > perhaps i am wrong somewhere? or there is some trick I need to use > > Please. I need all input since I stuck here with no idea what
There are various things you can do to speed things up: 1) Don't use models. Models make things easier, but they have overhead. This will provide a decent speedup. Of course, you won't be able to call any model methods if you do this. I doubt this will give you the performance you are looking for, though. DB[:products].select_all.each do |p| true end 2) Drop down to the connection level. This will make things much faster, but will be more difficult. You don't mention what adapter you are using, so I can't provide any example code beyond what gives you the connection: DB.synchronize do |conn| ... end Here conn is an underlying connection to the database. What class of object depends on the adapter. For example, if you are using the postgres adapter, is a PGConn object. This is the fastest way, but it makes your code adapter dependent. For what you are doing, it's what I'd recommend. To get even faster, you can write a ruby C extension that provides a method that accepts that connection object and uses the C database structures and functions to read the data and interface directly with gtk in C. I wouldn't do that unless I had to for performance reasons, though. Jeremy -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sequel-talk?hl=en.
