Home > OS >  runghc very slow (17-33 Seconds just for Printing an Array)
runghc very slow (17-33 Seconds just for Printing an Array)

Time:12-05

At my university i currently have a Lecture about Haskell. Now i got a Job to make a Program. We got this Sample File: https://pastebin.com/6wPdEgHZ

Starting from that, we have to develop the Program around it. The Functions simulate a Database-Access.

Since i dont like programming in WinHugs, i set up Visual Studio Code with GHC. I added a main-Function to print out Function-Outputs. It looks like this:

module Main where

main :: IO ()
main = print artikel

i added that to the top. Thats it. At first i wanted to output the Articles. That are the runghc-Outputs:

[Running] runghc "c:\Users\5CG949285X\Documents\DHBW\5_Semester\Funktionale Programmierung\restaurant.hs"
[(1,"Hamburger","Hauptgericht",8.0,6.0),(2,"Cheeseburger","Hauptgericht",9.0,6.5),(3,"Chickenburger","Hauptgericht",8.5,6.5),(4,"Pommes frites","Beilage",3.0,2.0),(5,"Wedges","Beilage",3.5,2.0),(6,"Cola","Getraenk",2.5,1.0),(7,"Eistee","Getraenk",2.0,1.0),(8,"Wasser","Getraenk",1.5,0.5)]

[Done] exited with code=0 in 24.527 seconds

[Running] runghc "c:\Users\5CG949285X\Documents\DHBW\5_Semester\Funktionale Programmierung\restaurant.hs"
[(1,"Hamburger","Hauptgericht",8.0,6.0),(2,"Cheeseburger","Hauptgericht",9.0,6.5),(3,"Chickenburger","Hauptgericht",8.5,6.5),(4,"Pommes frites","Beilage",3.0,2.0),(5,"Wedges","Beilage",3.5,2.0),(6,"Cola","Getraenk",2.5,1.0),(7,"Eistee","Getraenk",2.0,1.0),(8,"Wasser","Getraenk",1.5,0.5)]

[Done] exited with code=0 in 30.182 seconds

As u see, it takes very long. Is it just cause the file has VERY much code in it? Or did i do something wrong setting it up?

CodePudding user response:

If i let the file as it is, just put module Restaurant where on the top and add a second file, called "Main.hs" in the same directory, which looks as follows:

module Main where

import Restaurant

main :: IO ()
main = print artikel

it runs much faster.

If i run that Main.hs it looks like this:

[Running] runghc "c:\Users\5CG949285X\Documents\DHBW\5_Semester\Funktionale Programmierung\Main.hs"
[(1,"Hamburger","Hauptgericht",8.0,6.0),(2,"Cheeseburger","Hauptgericht",9.0,6.5),(3,"Chickenburger","Hauptgericht",8.5,6.5),(4,"Pommes frites","Beilage",3.0,2.0),(5,"Wedges","Beilage",3.5,2.0),(6,"Cola","Getraenk",2.5,1.0),(7,"Eistee","Getraenk",2.0,1.0),(8,"Wasser","Getraenk",1.5,0.5)]

[Done] exited with code=0 in 0.473 seconds

[Running] runghc "c:\Users\5CG949285X\Documents\DHBW\5_Semester\Funktionale Programmierung\Main.hs"
[(1,"Hamburger","Hauptgericht",8.0,6.0),(2,"Cheeseburger","Hauptgericht",9.0,6.5),(3,"Chickenburger","Hauptgericht",8.5,6.5),(4,"Pommes frites","Beilage",3.0,2.0),(5,"Wedges","Beilage",3.5,2.0),(6,"Cola","Getraenk",2.5,1.0),(7,"Eistee","Getraenk",2.0,1.0),(8,"Wasser","Getraenk",1.5,0.5)]

[Done] exited with code=0 in 0.434 seconds

[Running] runghc "c:\Users\5CG949285X\Documents\DHBW\5_Semester\Funktionale Programmierung\Main.hs"
[(1,"Hamburger","Hauptgericht",8.0,6.0),(2,"Cheeseburger","Hauptgericht",9.0,6.5),(3,"Chickenburger","Hauptgericht",8.5,6.5),(4,"Pommes frites","Beilage",3.0,2.0),(5,"Wedges","Beilage",3.5,2.0),(6,"Cola","Getraenk",2.5,1.0),(7,"Eistee","Getraenk",2.0,1.0),(8,"Wasser","Getraenk",1.5,0.5)]

[Done] exited with code=0 in 0.487 seconds

So MUCH faster and actually workable with. In the End, the Requirement was to deliver just a Single .hs File, that works in WinHugs. So i think i will keep working in my Main.hs now and consolidate it back to the original File, once im finished. Should work.

Thanks @all

  • Related