open System open System.IO open System.Diagnostics let time f = let watch = Stopwatch.StartNew() f() watch.Stop printfn "%A" watch.Elapsed let rec sum xs = match xs with | [] -> 0 | h::t -> h + sum(t) let random = new Random() let data = List.init 1000000 (fun _ -> random.Next(Int32.MaxValue)) let rec qs xs = match xs with | [] -> [] | [_] -> xs | h :: t -> qs([for i in t do if i<= h then yield i]) @ [h] @ qs([for i in t do if i>h then yield i]) let saveAs fn xs = use stream = File.CreateText(fn) for v in xs do stream.WriteLine(sprintf "%A" v) let saveData = do saveAs "or.txt" data do saveAs "so.txt" (qs data) time(fun _ -> printfn "sum = %A" (sum data)) time(fun _ -> printfn "sum = %A" (sum data)) time(fun _ -> qs data |> ignore) time(fun _ -> saveData |> ignore) printfn "done"
t.me/perfect0sight
Комментарии
Отправить комментарий