This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Learn more about F# at http://fsharp.org | |
// See the 'F# Tutorial' project for more help. | |
open MathNet.Numerics | |
open System.Numerics | |
//create a fractional approximation of pi | |
let rec series n q = | |
seq { | |
yield q * 4N / n | |
yield! series (n + 2N) (q * -1N) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// All you want to do is take a table in the database | |
// and show it as a table in the browser. | |
// How hard could it be? | |
// First you gotta know SQL or whatever other language/syntax your | |
// database uses to query it | |
var query = "SELECT TOP 100 * FROM THINGS ORDER BY DATE" | |
// Then you gotta import and learn to use some database driver to talk to your database | |
// Or alternatively learn to use its REST api and work with whatever format it returns |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Faster than the core lib filter in most scenarios. | |
// Core lib may be faster when filtering about half the data | |
// and the filtered data is randomy distributed in the array. | |
// Even in cases where it is a little slower, it allocates a lot | |
// less. Relieving GC overhead. | |
let inline filter (f: ^T -> bool) (array: ( ^T)[]) = | |
let len = array.Length | |
if array = null then invalidArg "array" "Array can not be null." | |
if len = 0 then invalidArg "array" "Array can not be empty." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let filter f (array: 'T[]) = | |
checkNonNull array | |
if sizeof<'T> < 4 then | |
let tmp = Array.zeroCreate array.Length | |
let mutable count = 0 | |
for i = 0 to array.Length - 1 do | |
let x = array.[i] | |
if f x then |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let arrayPartition f (array: _[]) = | |
checkNonNull array | |
//Hold both arrays in one of exact length | |
let res = Array.zeroCreate array.Length | |
let mutable upCount = 0 | |
let mutable downCount = array.Length-1 | |
for i = 0 to array.Length-1 do | |
let x = array.[i] | |
if f x then |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let choose f (array: 'T[]) = | |
let inputLength = array.Length | |
let isChosen : bool [] = Array.zeroCreate inputLength | |
let results : 'U [] = Array.zeroCreate inputLength | |
Parallel.For(0, inputLength, (fun i -> | |
match f array.[i] with |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let filterNew f (array: _[]) = | |
checkNonNull "array" array | |
let mutable i = 0 | |
while i < array.Length && not (f array.[i]) do | |
i <- i + 1 | |
if i <> array.Length then | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// BenchmarkDotNet Notes: | |
/// Docs/Github: https://github.com/PerfDotNet/BenchmarkDotNet#getting-started | |
/// | |
/// This benchmarking suite will perform JIT warmups, collect system environment data | |
/// run multiple trials, and produce convenient reports. | |
/// You will find csv, markdown, and and html versions of the reports in .\BenchmarkDotNet.Artifacts\results | |
/// after running the tests. | |
/// | |
/// Be sure to run tests in Release mode, optimizations on, etc. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let filterUltra f (array : 'T[]) = | |
let inline computeChunk (x:float32) = | |
int((float32)array.Length*x) | |
let chunkProgression = | |
match sizeof<'T> * array.Length with | |
| x when x < 4096 -> [|array.Length|] | |
| x when x < 65536 -> [|computeChunk 0.25f;computeChunk 0.76f|] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using System.Linq; | |
using BenchmarkDotNet.Attributes; | |
using BenchmarkDotNet.Running; | |
using BenchmarkDotNet.Configs; | |
using BenchmarkDotNet.Jobs; | |
using BenchmarkDotNet.Diagnostics.Windows; | |
namespace bigo |
OlderNewer