Giter Site home page Giter Site logo

Comments (4)

bartavelle avatar bartavelle commented on September 26, 2024

It's 15% faster with MVars on my computer.

from skynet.

osa1 avatar osa1 commented on September 26, 2024

Makes sense, as channels are more general than what's needed here.

Results on my laptop: (first one is the MVar version)

➜  haskell git:(master) ✗ time (./Skynet2 +RTS -N4)                                  
Result: 499999500000 in 1.90832s
( ./Skynet2 +RTS -N4; )  6.39s user 1.64s system 329% cpu 2.433 total

➜  haskell git:(master) ✗ time (./Skynet +RTS -N4) 
Result: 499999500000 in 2.027485s
( ./Skynet +RTS -N4; )  6.92s user 1.38s system 356% cpu 2.327 total

from skynet.

bartavelle avatar bartavelle commented on September 26, 2024

Also, I would have done this (even though we are not in the actor paradigm now) :

{-# LANGUAGE BangPatterns #-}
module Main (main) where

import Data.Time.Clock (getCurrentTime, diffUTCTime)

import Control.Parallel.Strategies

skynet :: Int -> Int -> Int -> Int
skynet num size dv
    | size == 1 = num
    | otherwise = sum (parMap rpar subcompute [0 .. dv-1])
    where
        subcompute i = let subNum  = num + i * sizeDiv
                           sizeDiv = size `quot` dv
                       in  skynet subNum sizeDiv dv
main :: IO ()
main = do
    start  <- getCurrentTime
    let !result = skynet 0 1000000 10
    end    <- getCurrentTime
    putStrLn $ concat ["Result: ", show result, " in ", show (diffUTCTime end start)]

And it is much faster (0.027s on my computer).

from skynet.

bitemyapp avatar bitemyapp commented on September 26, 2024

@bartavelle thank you for submitting these, I am going to PR this and other fixes!

from skynet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.