(|>)
और (>>>)
को रेखांकित होने तक कोई अंतर नहीं होना चाहिए।
==================== Tidy Core ====================
Result size of Tidy Core = {terms: 82, types: 104, coercions: 0}
-- RHS size: {terms: 9, types: 11, coercions: 0}
>>>_rqe
>>>_rqe =
\ @ a_a1cE @ b_a1cF @ c_a1cG f_aqr g_aqs x_aqt ->
g_aqs (f_aqr x_aqt)
-- RHS size: {terms: 2, types: 0, coercions: 0}
$trModule1_r1gR
$trModule1_r1gR = TrNameS "main"#
-- RHS size: {terms: 2, types: 0, coercions: 0}
$trModule2_r1h6
$trModule2_r1h6 = TrNameS "Main"#
-- RHS size: {terms: 3, types: 0, coercions: 0}
$trModule
$trModule = Module $trModule1_r1gR $trModule2_r1h6
-- RHS size: {terms: 58, types: 73, coercions: 0}
main
main =
>>
$fMonadIO
(>>=
$fMonadIO
getLine
(. putStrLn
(>>>_rqe
(>>>_rqe (filter isUpper) (length $fFoldable[]))
(show $fShowInt))))
(>>
$fMonadIO
(>>=
$fMonadIO
getLine
(. putStrLn
(\ x_a10M ->
show $fShowInt (length $fFoldable[] (filter isUpper x_a10M)))))
(>>
$fMonadIO
(>>=
$fMonadIO
getLine
(. putStrLn
(. (show $fShowInt) (. (length $fFoldable[]) (filter isUpper)))))
(>>=
$fMonadIO
getLine
(. putStrLn
(\ x_a10N ->
show $fShowInt (length $fFoldable[] (filter isUpper x_a10N)))))))
-- RHS size: {terms: 2, types: 1, coercions: 0}
main
main = runMainIO main
तो >>>
नहीं करता है: हम हम मिल -ddump-simpl -dsuppress-all -O0
के साथ हमारे कोड संकलन तो
import Data.Char (isUpper)
{-# INLINE (|>) #-}
(|>) :: a -> (a -> b) -> b
(|>) x f = f x
{-# INLINE (>>>) #-}
(>>>) :: (a -> b) -> (b -> c) -> a -> c
(>>>) f g x = g (f x)
compositionF :: String -> String
compositionF = filter isUpper >>> length >>> show
applicationF :: String -> String
applicationF x = x |> filter isUpper |> length |> show
compositionH :: String -> String
compositionH = show . length . filter isUpper
applicationH :: String -> String
applicationH x = show $ length $ filter isUpper $ x
main :: IO()
main = do
getLine >>= putStrLn . compositionF -- using the functions
getLine >>= putStrLn . applicationF -- to make sure that
getLine >>= putStrLn . compositionH -- we actually get the
getLine >>= putStrLn . applicationH -- corresponding GHC core
: चलो एक उदाहरण के चार अलग-अलग काम करता है, एफ # शैली में दो, और हास्केल शैली में दो का उपयोग करता है लिखते हैं अगर हम अनुकूलन सक्षम नहीं करते हैं तो इनलाइन नहीं किया जाएगा। अगर हम अनुकूलन सक्षम करते हैं, तो आपको >>>
या (.)
बिल्कुल नहीं दिखाई देगा। हमारे कार्य थोड़ा अलग हैं, क्योंकि (.)
उस चरण में रेखांकित नहीं होते हैं, लेकिन यह कुछ हद तक अपेक्षित है।
हम अपने कार्यों के लिए {-# NOINLINE … #-}
जोड़ सकते हैं और optimiziations हम देखते हैं कि चार कार्य बिल्कुल अलग नहीं होगा सक्षम करते हैं:
$ ghc -ddump-simpl -dsuppress-all -O2 Example.hs
[1 of 1] Compiling Main (Example.hs, Example.o)
==================== Tidy Core ====================
Result size of Tidy Core = {terms: 261, types: 255, coercions: 29}
-- RHS size: {terms: 2, types: 0, coercions: 0}
$trModule2
$trModule2 = TrNameS "main"#
-- RHS size: {terms: 2, types: 0, coercions: 0}
$trModule1
$trModule1 = TrNameS "Main"#
-- RHS size: {terms: 3, types: 0, coercions: 0}
$trModule
$trModule = Module $trModule2 $trModule1
Rec {
-- RHS size: {terms: 29, types: 20, coercions: 0}
$sgo_r574
$sgo_r574 =
\ sc_s55y sc1_s55x ->
case sc1_s55x of _ {
[] -> I# sc_s55y;
: y_a2j9 ys_a2ja ->
case y_a2j9 of _ { C# c#_a2hF ->
case {__pkg_ccall base-4.9.1.0 u_iswupper Int#
-> State# RealWorld -> (# State# RealWorld, Int# #)}_a2hE
(ord# c#_a2hF) realWorld#
of _ { (# ds_a2hJ, ds1_a2hK #) ->
case ds1_a2hK of _ {
__DEFAULT -> $sgo_r574 (+# sc_s55y 1#) ys_a2ja;
0# -> $sgo_r574 sc_s55y ys_a2ja
}
}
}
}
end Rec }
-- RHS size: {terms: 15, types: 14, coercions: 0}
applicationH
applicationH =
\ x_a12X ->
case $sgo_r574 0# x_a12X of _ { I# ww3_a2iO ->
case $wshowSignedInt 0# ww3_a2iO []
of _ { (# ww5_a2iS, ww6_a2iT #) ->
: ww5_a2iS ww6_a2iT
}
}
Rec {
-- RHS size: {terms: 29, types: 20, coercions: 0}
$sgo1_r575
$sgo1_r575 =
\ sc_s55r sc1_s55q ->
case sc1_s55q of _ {
[] -> I# sc_s55r;
: y_a2j9 ys_a2ja ->
case y_a2j9 of _ { C# c#_a2hF ->
case {__pkg_ccall base-4.9.1.0 u_iswupper Int#
-> State# RealWorld -> (# State# RealWorld, Int# #)}_a2hE
(ord# c#_a2hF) realWorld#
of _ { (# ds_a2hJ, ds1_a2hK #) ->
case ds1_a2hK of _ {
__DEFAULT -> $sgo1_r575 (+# sc_s55r 1#) ys_a2ja;
0# -> $sgo1_r575 sc_s55r ys_a2ja
}
}
}
}
end Rec }
-- RHS size: {terms: 15, types: 15, coercions: 0}
compositionH
compositionH =
\ x_a1jF ->
case $sgo1_r575 0# x_a1jF of _ { I# ww3_a2iO ->
case $wshowSignedInt 0# ww3_a2iO []
of _ { (# ww5_a2iS, ww6_a2iT #) ->
: ww5_a2iS ww6_a2iT
}
}
Rec {
-- RHS size: {terms: 29, types: 20, coercions: 0}
$sgo2_r576
$sgo2_r576 =
\ sc_s55k sc1_s55j ->
case sc1_s55j of _ {
[] -> I# sc_s55k;
: y_a2j9 ys_a2ja ->
case y_a2j9 of _ { C# c#_a2hF ->
case {__pkg_ccall base-4.9.1.0 u_iswupper Int#
-> State# RealWorld -> (# State# RealWorld, Int# #)}_a2hE
(ord# c#_a2hF) realWorld#
of _ { (# ds_a2hJ, ds1_a2hK #) ->
case ds1_a2hK of _ {
__DEFAULT -> $sgo2_r576 (+# sc_s55k 1#) ys_a2ja;
0# -> $sgo2_r576 sc_s55k ys_a2ja
}
}
}
}
end Rec }
-- RHS size: {terms: 15, types: 15, coercions: 0}
compositionF
compositionF =
\ x_a1jF ->
case $sgo2_r576 0# x_a1jF of _ { I# ww3_a2iO ->
case $wshowSignedInt 0# ww3_a2iO []
of _ { (# ww5_a2iS, ww6_a2iT #) ->
: ww5_a2iS ww6_a2iT
}
}
Rec {
-- RHS size: {terms: 29, types: 20, coercions: 0}
$sgo3_r577
$sgo3_r577 =
\ sc_s55d sc1_s55c ->
case sc1_s55c of _ {
[] -> I# sc_s55d;
: y_a2j9 ys_a2ja ->
case y_a2j9 of _ { C# c#_a2hF ->
case {__pkg_ccall base-4.9.1.0 u_iswupper Int#
-> State# RealWorld -> (# State# RealWorld, Int# #)}_a2hE
(ord# c#_a2hF) realWorld#
of _ { (# ds_a2hJ, ds1_a2hK #) ->
case ds1_a2hK of _ {
__DEFAULT -> $sgo3_r577 (+# sc_s55d 1#) ys_a2ja;
0# -> $sgo3_r577 sc_s55d ys_a2ja
}
}
}
}
end Rec }
-- RHS size: {terms: 15, types: 14, coercions: 0}
applicationF
applicationF =
\ x_a12W ->
case $sgo3_r577 0# x_a12W of _ { I# ww3_a2iO ->
case $wshowSignedInt 0# ww3_a2iO []
of _ { (# ww5_a2iS, ww6_a2iT #) ->
: ww5_a2iS ww6_a2iT
}
}
...
सभी go
कार्यों बिल्कुल वैसा ही (बिना चर नाम) हैं, और application*
है composition*
जैसा ही है। तो आगे बढ़ें और हास्केल में अपना स्वयं का एफ # प्रस्ताव बनाएं, कोई प्रदर्शन समस्या नहीं होनी चाहिए।
आप परीक्षण कर देखने के लिए जो तेजी से होता है की कोशिश की है? – AJFarmar
@AJFarmar मैंने इसके बारे में सोचा लेकिन क्या हैकेल में निष्पादन समय मापने का कोई तरीका है? –
यदि हैकेल में निष्पादन समय को मापने का कोई तरीका नहीं है, तो आपका प्रश्न "इनमें से कौन सा तेज़ है" असंभव होगा। – amalloy