tags:

views:

110

answers:

2

I read the documentation and some articles that talk about the package, but I'm new to Haskell and did not understand much but I tried ....

Below is what I did:

module Main where  
{-# LANGUAGE BangPatterns #-}   
import Control.Parallel(par,pseq)  
import Control.Exception  
import Data.List  
import IO  
import Data.Char  
import Criterion.Main (defaultMain, bench)  

learquivo :: FilePath -> IO ([[Int]])  
learquivo "mkList1.txt"  = do   
    conteudo <- readFile "mkList1.txt" 
    return (read conteudo) 


main = defaultMain [  
    bench "map sort learquivo" $ \n -> map sort learquivo
    ]

As it did the following error occurred:

Couldn't match expected type [[a]]
       against inferred type FilePath -> IO [[Int]]
+2  A: 

The problem is this: map sort learquivo

sort expects a list, and so map sort expects a list of lists ([[a]]), whereas the type of learquivo is of type FilePath -> IO [[Int]].

You probably want something like:

main = do
    contents <- learquivo "mkList1.txt"
    defaultMain [
       bench "map sort learquivo" $ \n -> map sort contents
    ]

There are various things in your code that could be cleaned up, but that should get you going.

Ganesh Sittampalam
Ganesh Sittampalam, true, it was missing. I'm slowly doing to try to understand what is happening.
Gmp
+2  A: 

Just so you have how I usually run it, using the nf or whnf functions, I'll give my code:

import Data.List
import Criterion.Main

main :: IO ()
main = do
   -- content <- learquivo "mkList1.txt"  
   let content = [ [big, big - step.. 0] | big <- [1000..1010], step <- [1..5]] :: [[Int]]
   defaultMain
        [ bench "benchmark-name" (nf (map sort) content)]

EDIT: If you like this then also give plotting a try:

module Main where

import Data.List
import Criterion.Main
import Criterion.Config
import Criterion.MultiMap as M

main :: IO ()
main = do
   let myConfig = defaultConfig {
              -- Always display an 800x600 window with curves.
              cfgPlot = M.singleton KernelDensity (Window 800 600)
              }
   let content = [ [big, big-step.. 0] | big <- [1000..1010], step <- [1..5]] :: [[Int]]
   defaultMainWith myConfig (return ())
        [ bench "benchmark-name" (nf (map sort) content)]
TomMD
TomMD, thank you again.I did several tests, changing the place of parentheses, but none worked, had not yet done so, now the program is running, it really is easier with Criterion without facing the problems of lazy evaluation.
Gmp
TomMD, maybe my Criterion not fully working, that you put this command should open a window with a graphic is that?
Gmp
Gmp, yes the second bit of code is a complete program that should open a window with a plot showing the execution time density.
TomMD
Not opened, hehehehe, is there some flaw in the installation of Creterion?
Gmp
Appeared only stimating clock resolution, with data from the execution.
Gmp
A I'm sorry I made a mistake in the program so it did not open the window.
Gmp
It runs on windows?
Gmp
ERROR: output type Window 800 600 not supported on this platform
Gmp