text stringlengths 0 601k |
|---|
let edit_space_age ( ps : ( string * json ) list ) : ( string * string ) list = let edit = function | ( " planet " , v ) -> ( " planet " , json_to_string v |> strip_quotes ) | ( k , v ) -> ( k , json_to_string v ) in List . map ps ~ f : edit |
let null_to_option = function ` Null -> " None " | x -> Printf . sprintf " ( Some % s ) " ( json_to_string x ) |
let edit_palindrome_products ( ps : ( string * json ) list ) : ( string * string ) list = let edit = function | ( " property " , v ) -> ( " property " , json_to_string v |> strip_quotes ) | ( " expected " , ` Assoc kvs ) -> let find = List . Assoc . find kvs ~ equal : String . equal in let open Option . Monad_infix in ... |
let edit_bowling ( ps : ( string * json ) list ) : ( string * string ) list = let edit = function | ( " property " , v ) -> ( " property " , json_to_string v |> strip_quotes ) | ( " roll " , ` Int n ) -> ( " roll " , let s = Int . to_string n in if n < 0 then ( " ( " ^ s ^ " ) " ) else s ) | ( " expected " , v ) -> ( "... |
let edit_binary_search ( ps : ( string * json ) list ) : ( string * string ) list = let open Yojson . Basic . Util in let as_array_string xs = let xs = to_list xs |> List . map ~ f : to_int |> List . map ~ f : Int . to_string in " [ " | ^ String . concat ~ sep " ; : " xs ^ " ] " | in let edit = function | ( " array " ,... |
let edit_change ( ps : ( string * json ) list ) : ( string * string ) list = let edit = function | ( " target " , ` Int i ) -> ( " target " , Printf . sprintf ( if i < 0 then " ( % i ) " else " % i " ) i ) | ( " expected " , v ) -> ( " expected " , match v with | ` List xs -> " ( Ok [ " ^ ( String . concat ~ sep " ; : ... |
let edit_rectangles ( ps : ( string * json ) list ) : ( string * string ) list = let format_field l = let sep = if List . length l > 1 then " ; \ n " else " " in let fmt = if List . length l > 1 then Printf . sprintf " [ |\ n % s ; \ n ] " | else Printf . sprintf " [ |% s ] " | in l |> List . map ~ f : json_to_string |... |
let edit_etl ( ps : ( string * json ) list ) : ( string * string ) list = let edit = function | ( " expected " , ` Assoc l ) -> let grouped = l |> List . map ~ f ( : fun ( k , v ) -> Printf . sprintf " ( ' % s ' , % s ) " k ( json_to_string v ) ) |> List . groupi ~ break ( : fun i _ _ -> Int . ( i % 5 = 0 ) ) in if Lis... |
let rec edit_expected ( ~ f : json -> string ) ( parameters : ( string * json ) list ) = match parameters with | [ ] -> [ ] | ( " expected " , v ) :: rest -> ( " expected " , f v ) :: edit_expected ~ f rest | ( k , v ) :: rest -> ( k , json_to_string v ) :: edit_expected ~ f rest |
let unwrap_strings ( ps : ( string * json ) list ) : ( string * string ) list option = let edit = function | ( _ , ` String s ) -> ( " params " , s ) | ( k , v ) -> ( k , json_to_string v ) in ps |> List . map ~ f : edit |> Option . return |
let edit_parameters ( ~ slug : string ) ( parameters : ( string * json ) list ) = match ( slug , parameters ) with | ( " all - your - base " , ps ) -> edit_all_your_base ps |> Option . return | ( " allergies " , ps ) -> edit_allergies ps |> Option . return | ( " beer - song " , ps ) -> edit_expected ~ f : edit_beer_son... |
let edit_difference_of_squares_case ( case : json ) : json = let f = function | ( " property " , ` String " squareOfSum " ) -> ( " property " , ` String " square_of_sum " ) | ( " property " , ` String " sumOfSquares " ) -> ( " property " , ` String " sum_of_squares " ) | ( " property " , ` String " differenceOfSquares ... |
let edit_run_length_encoding_case ( case : json ) : json = let f = function | ( " property " , ` String " consistency " ) -> ( " property " , ` String " encode |> decode " ) | ( " slug " , ` String " run_length_encode_a_string " ) -> ( " slug " , ` String " encode " ) | ( " slug " , ` String " run_length_decode_a_strin... |
let edit_allergies_case ( case : json ) : json = let f = function | ( " property " , ` String " allergicTo " ) -> [ ( " property " , ` String " allergic_to " ) ; ( " assertion " , ` String " aeb " ) ] | ( " property " , ` String " list " ) -> [ ( " property " , ` String " allergies " ) ; ( " assertion " , ` String " ae... |
let edit_custom_set_case ( case : json ) : json = let get_input ~ key = Util . member " input " case |> Util . member key in let get_list ~ key = get_input ~ key |> ( function ` List l -> l | _ -> [ ] ) |> List . map ~ f : Util . to_int |> List . map ~ f : Int . to_string |> list_to_string in let module_name = ( " modu... |
let edit_grade_school_case ( case : json ) : json = let string_of_students ( ) = Util . member " input " case |> Util . member " students " |> Util . to_list |> List . filter_map ~ f ( : fun student -> match student with | ` List ( ( ` String name ) ( ` :: Int grade ) :: _ ) -> Some ( Printf . sprintf " add " \% s " \ ... |
let edit_case ( ~ slug : string ) ( case : json ) = match ( slug , case ) with | ( " allergies " , case ) -> edit_allergies_case case | ( " custom - set " , case ) -> edit_custom_set_case case | ( " grade - school " , case ) -> edit_grade_school_case case | ( " difference - of - squares " , case ) -> edit_difference_of... |
module Pre = struct type ' a t = ' a GenClone . prependable let of_gen xs = xs |> GenMList . of_gen |> GenMList . to_clonable |> GenClone . to_prependable let of_list xs = Gen . of_list xs |> of_gen let map f xs = Gen . map f xs # gen |> of_gen let empty ( ) = Gen . empty |> of_gen let singleton a = Gen . singleton a |... |
module Seq = struct type ' a t = ' a GenClone . clonable let of_gen xs = xs |> GenMList . of_gen |> GenMList . to_clonable let of_pre ( xs : ' a Pre . t ) = xs # gen |> of_gen let of_list xs = Gen . of_list xs |> of_gen let to_list xs = xs # gen |> Gen . to_list let map f xs = GenClone . map f xs let empty ( ) = Gen . ... |
module type Enum = sig module T : TC1 val enum : ' a Seq . t -> ' a T . el Seq . t val to_list : ( ' a , T . co ) ap Seq . t -> ' a T . el list end |
module type Pack = sig include Enum val pack : T . co enum end |
module Void : sig type ' a t module T : TC1 with type ' a el = ' a t include Pack with module T := T struct module Def = struct type ' a t module T = TC1 ( struct type nonrec ' a t = ' a t end ) let enum xs = Seq . empty ( ) let to_list xs = Seq . map T . el xs |> Seq . to_list end include Def let pack : Def . T . co e... |
module Unit : sig type ' a t = Unit module T : TC1 with type ' a el = ' a t include Pack with module T := T struct module Def = struct type ' a t = Unit module T = TC1 ( struct type nonrec ' a t = ' a t end ) let enum xs = match Gen . next xs # gen with | None -> Seq . singleton Unit | Some ( _ ) -> Seq . empty ( ) let... |
module Add ( F : Pack ) ( G : Pack ) : sig type ' a t = | Inl of ' a F . T . el | Inr of ' a G . T . el module T : TC1 with type ' a el = ' a t include Pack with module T := T struct module Def = struct type ' a t = | Inl of ' a F . T . el | Inr of ' a G . T . el module T = TC1 ( struct type nonrec ' a t = ' a t end ) ... |
module Mul ( F : Pack ) ( G : Pack ) : sig type ' a t = ' a F . T . el * ' a G . T . el module T : TC1 with type ' a el = ' a t include Pack with module T := T struct module Def = struct type ' a t = ' a F . T . el * ' a G . T . el module T = TC1 ( struct type nonrec ' a t = ' a t end ) let enum xs = let go0 ( fls , gl... |
module Sing : sig type ' a t = X of ' a module T : TC1 with type ' a el = ' a t include Pack with module T := T struct module Def = struct type ' a t = X of ' a module T = TC1 ( struct type nonrec ' a t = ' a t end ) let enum xs = begin match Gen . next xs # gen with | None -> Seq . empty ( ) | Some ( x ) -> begin matc... |
module Linear : sig type ' a t = ' a list module T : TC1 with type ' a el = ' a t include Pack with module T := T struct module Def = struct type ' a t = ' a list module T = TC1 ( struct type nonrec ' a t = ' a t end ) let enum = Seq . permutations let to_list xs = Seq . map T . el xs |> Seq . to_list end include Def l... |
module Species = struct let enum ( type f ) ( e : f enum ) xs = let module E = ( val e ) in Seq . map E . T . co ( E . enum xs ) end |
module Test = struct let ex0 : int Void . t list = Species . enum Void . pack ( Seq . of_list [ 0 ; 1 ; 2 ; 3 ; 4 ] ) |> Void . to_list let ex1 : int Sing . t list = Species . enum Sing . pack ( Seq . of_list [ 0 ; 1 ; 2 ; 3 ; 4 ] ) |> Sing . to_list let ex2 : int Sing . t list = Species . enum Sing . pack ( Seq . sing... |
let test_mk_and2 test_ctxt = let ctx = bracket_mk_context test_ctxt in let t = Yices . mk_true ctx and f = Yices . mk_false ctx in Yices . push ctx ; Yices . assert_simple ctx ( Yices . mk_and2 ctx t t ) ; assert_equal Yices . True ( Yices . check ctx ) ; Yices . pop ctx ; Yices . push ctx ; Yices . assert_simple ctx (... |
let test_mk_or2 test_ctxt = let ctx = bracket_mk_context test_ctxt in let t = Yices . mk_true ctx and f = Yices . mk_false ctx in Yices . push ctx ; Yices . assert_simple ctx ( Yices . mk_or2 ctx t t ) ; assert_equal Yices . True ( Yices . check ctx ) ; Yices . pop ctx ; Yices . push ctx ; Yices . assert_simple ctx ( Y... |
let test_mk_nand2 test_ctxt = let ctx = bracket_mk_context test_ctxt in let t = Yices . mk_true ctx and f = Yices . mk_false ctx in Yices . push ctx ; Yices . assert_simple ctx ( Yices . mk_nand2 ctx t t ) ; assert_equal Yices . False ( Yices . check ctx ) ; Yices . pop ctx ; Yices . push ctx ; Yices . assert_simple ct... |
let test_mk_nand test_ctxt = let ctx = bracket_mk_context test_ctxt in let t = Yices . mk_true ctx and f = Yices . mk_false ctx in Yices . push ctx ; Yices . assert_simple ctx ( Yices . mk_nand ctx [ | t ; t ; t ; t ] ) ; | assert_equal Yices . False ( Yices . check ctx ) ; Yices . pop ctx ; Yices . push ctx ; Yices . ... |
let test_mk_nor2 test_ctxt = let ctx = bracket_mk_context test_ctxt in let t = Yices . mk_true ctx and f = Yices . mk_false ctx in Yices . push ctx ; Yices . assert_simple ctx ( Yices . mk_nor2 ctx t t ) ; assert_equal Yices . False ( Yices . check ctx ) ; Yices . pop ctx ; Yices . push ctx ; Yices . assert_simple ctx ... |
let test_mk_nor test_ctxt = let ctx = bracket_mk_context test_ctxt in let t = Yices . mk_true ctx and f = Yices . mk_false ctx in Yices . push ctx ; Yices . assert_simple ctx ( Yices . mk_nor ctx [ | t ; t ; t ; t ] ) ; | assert_equal Yices . False ( Yices . check ctx ) ; Yices . pop ctx ; Yices . push ctx ; Yices . as... |
let test_mk_sum2 test_ctxt = let ctx = bracket_mk_context test_ctxt in let n = Yices . mk_num ctx in Yices . assert_simple ctx ( Yices . mk_eq ctx ( n 3 ) ( Yices . mk_sum2 ctx ( n 1 ) ( n 2 ) ) ) ; Yices . assert_simple ctx ( Yices . mk_eq ctx ( n ( - 2 ) ) ( Yices . mk_sum2 ctx ( n 0 ) ( n ( - 2 ) ) ) ) ; assert_equa... |
let test_mk_sub2 test_ctxt = let ctx = bracket_mk_context test_ctxt in let n = Yices . mk_num ctx in Yices . assert_simple ctx ( Yices . mk_eq ctx ( n 56 ) ( Yices . mk_sub2 ctx ( n 81 ) ( n 25 ) ) ) ; Yices . assert_simple ctx ( Yices . mk_eq ctx ( n ( - 502 ) ) ( Yices . mk_sub2 ctx ( n ( - 2 ) ) ( n 500 ) ) ) ; asse... |
let test_mk_mul2 test_ctxt = let ctx = bracket_mk_context test_ctxt in let n = Yices . mk_num ctx in Yices . assert_simple ctx ( Yices . mk_eq ctx ( n 952 ) ( Yices . mk_mul2 ctx ( n 56 ) ( n 17 ) ) ) ; Yices . assert_simple ctx ( Yices . mk_eq ctx ( n 0 ) ( Yices . mk_mul2 ctx ( n 0 ) ( n 1548 ) ) ) ; assert_equal Yic... |
let test_mk_and_nil test_ctxt = let ctx = bracket_mk_context test_ctxt in Yices . assert_simple ctx ( Yices . mk_and ctx [ ] ) ; || assert_equal Yices . True ( Yices . check ctx ) ; ; |
let test_mk_or_nil test_ctxt = let ctx = bracket_mk_context test_ctxt in Yices . assert_simple ctx ( Yices . mk_or ctx [ ] ) ; || assert_equal Yices . False ( Yices . check ctx ) ; ; |
let test_mk_nand_nil test_ctxt = let ctx = bracket_mk_context test_ctxt in Yices . assert_simple ctx ( Yices . mk_nand ctx [ ] ) ; || assert_equal Yices . False ( Yices . check ctx ) ; ; |
let test_mk_nor_nil test_ctxt = let ctx = bracket_mk_context test_ctxt in Yices . assert_simple ctx ( Yices . mk_nor ctx [ ] ) ; || assert_equal Yices . True ( Yices . check ctx ) ; ; |
let test_mk_sum_nil test_ctxt = let ctx = bracket_mk_context test_ctxt in let n = Yices . mk_num ctx in Yices . assert_simple ctx ( Yices . mk_eq ctx ( n 0 ) ( Yices . mk_sum ctx [ ] ) ) ; || assert_equal Yices . True ( Yices . check ctx ) ; Yices . reset ctx ; Yices . assert_simple ctx ( Yices . mk_eq ctx ( n 6 ) ( Yi... |
let test_mk_sub_nil test_ctxt = let ctx = bracket_mk_context test_ctxt in assert_raises ( Invalid_argument " mk_sub " ) ( fun ( ) -> Yices . mk_sub ctx [ ] ) ; || let n = Yices . mk_num ctx in Yices . assert_simple ctx ( Yices . mk_eq ctx ( n 6 ) ( Yices . mk_sub ctx [ | n 12 ; n 1 ; n 2 ; n 3 ] ) ) ; | assert_equal ~ ... |
let test_mk_mul_nil test_ctxt = let ctx = bracket_mk_context test_ctxt in let n = Yices . mk_num ctx in Yices . assert_simple ctx ( Yices . mk_eq ctx ( n 1 ) ( Yices . mk_mul ctx [ ] ) ) ; || assert_equal Yices . True ( Yices . check ctx ) ; Yices . reset ctx ; Yices . assert_simple ctx ( Yices . mk_eq ctx ( n 6 ) ( Yi... |
let test_mk_bv_constant_nil test_ctxt = let ctx = bracket_mk_context test_ctxt in ignore ( Yices . mk_bv_constant ctx 0 546l ) |
let test_mk_bv_constant_from_int test_ctxt = let ctx = bracket_mk_context test_ctxt in assert_raises ( Invalid_argument " mk_bv_constant_from_int " ) ( fun ( ) -> Yices . mk_bv_constant_from_int ctx 0 455 ) ; let a = Yices . mk_bv_constant_from_int ctx 8 85 in let b = Yices . mk_bv_constant ctx 8 85l in Yices . assert_... |
let tests = [ " mk_nand " >:: test_mk_nand ; " mk_nor " >:: test_mk_nor ; " binary shortcuts " >::: [ " mk_and2 " >:: test_mk_and2 ; " mk_or2 " >:: test_mk_or2 ; " mk_nand2 " >:: test_mk_nand2 ; " mk_nor2 " >:: test_mk_nor2 ; " mk_sum2 " >:: test_mk_sum2 ; " mk_sub2 " >:: test_mk_sub2 ; " mk_mul2 " >:: test_mk_mul2 ; ]... |
let eval_A cache i j = cache . ( i ) . ( j ) |
let eval_A_times_u cache u v = let n = Array . length v - 1 in for i = 0 to n do let vi = ref 0 . in for j = 0 to n do vi := ! vi . + eval_A cache i j . * u . ( j ) done ; v . ( i ) <- ! vi done |
let eval_At_times_u cache u v = let n = Array . length v - 1 in for i = 0 to n do let vi = ref 0 . in for j = 0 to n do vi := ! vi . + eval_A cache j i . * u . ( j ) done ; v . ( i ) <- ! vi done |
let eval_AtA_times_u cache u v = let w = Array . make ( Array . length u ) 0 . 0 in eval_A_times_u cache u w ; eval_At_times_u cache w v |
let eval_A i j = 1 . . / float ( ( i + j ) ( * i + j + 1 ) / 2 + i + 1 ) |
let n = try int_of_string ( Array . get Sys . argv 1 ) with _ -> 2000 |
let ( ) = let cache = Array . init n ( fun i -> let u = Array . make n 1 . 0 and v = Array . make n 0 . 0 in for i = 0 to 9 do eval_AtA_times_u cache u v ; eval_AtA_times_u cache v u done ; let vv = ref 0 . 0 and vBv = ref 0 . 0 in for i = 0 to n - 1 do vv := ! vv . + v . ( i ) . * v . ( i ) ; vBv := ! vBv . + u . ( i ... |
let line = ref 1 |
let parse ? repl ( : repl = false ) ? print ( : print = false ) ? dot ( : dot = false ) cin = let lexbuf = Lexing . from_channel cin in let defs = ref [ ] in try while true do try let result = SpecParser . file SpecLexer . token lexbuf in defs := ! defs [ @ result ] ; incr line ; if print then ( print_endline ( SpecCor... |
let parseFile filename = parse ( open_in filename ) |
type ' a j = ' a -> Yojson . Safe . t |
module type Json = sig val r1 : r1 j val r2 : r2 j val r3 : r3 j val r4 : r4 j val r5 : r5 j val r6 : r6 j val r7 : r7 j val r8 : r8 j val j1 : j1 j val j2 : j2 j val j3 : j3 j val j4 : j4 j val o1 : o1 j val o2 : o2 j val t1 : t1 j val t2 : t2 j val v1list : v1list j val v2 : v2 j val v3list : v3list j val ages : ages... |
module Make ( J : Json ) = struct open J let massive_json = ` List [ r1 { r1 = " testing " } ; r2 { r2 = Some 2 } ; r2 { r2 = None } ; r3 { r3 = Some 3 } ; r3 { r3 = None } ; r4 { r4 = true } ; r5 { r5 = Some 5 } ; r5 { r5 = None } ; r6 { r6 = 6 } ; r6 { r6 = 42 } ; r7 { r7 = - 1_000 } ; r8 { r888 = [ 1 ; 2 ; 3 ] } ; j... |
let ( ^/ ) = Filename . concat |
let specs_directory = Filename . parent_dir_name ^/ " specs " |
type test = { from_file : string ; name : string ; data : J . t ; partials : ( Mustache . name * Mustache . t ) t list ; template : string ; expected : string ; desc : string } |
let apply_mustache test = let tmpl = try Mustache . of_string test . template with e -> Printf . eprintf " Parsing of test % s from % s failed . \ n " test . name test . from_file ; raise e in let partials name = try Some ( List . assoc name test . partials ) partials with Not_found -> None in let rendered = try Mustac... |
let load_file f = let ic = open_in f in let n = in_channel_length ic in let s = Bytes . create n in really_input ic s 0 n ; close_in ic ; s |
let j_of_data : J . value -> J . t = function | ` O l -> ` O l | _ -> failwith " Incorrect json data " |
let load_test_file f = let test_j = load_file ( specs_directory ^/ f ) f |> Bytes . to_string |> J . from_string |> J . value in let test_of_json j = let test_name = J . find j [ " name " ] |> J . get_string in let parse_partials j = if not ( J . mem j [ " partials " ] ) then [ ] else J . find j [ " partials " ] |> J .... |
let assert_equal x y _ = assert_equal ~ printer ( : fun s -> s ) s x y |
let mktest test = test . name >:: assert_equal test . expected ( apply_mustache test ) test |
let specs = [ " comments . json " ; " inheritance . json " ; " interpolation . json " ; " inverted . json " ; " partials . json " ; " sections . json " ] |
let tests = " Mustache specs test suite " >::: List . map ( fun specfile -> " Test suite from " ^ specfile >::: ( load_test_file specfile |> List . map mktest ) mktest ) mktest specs |
let ( ) = run_test_tt_main tests |
module Time = struct let time ~ n f a = let t1 = Sys . time ( ) in for _ = 1 to n do ignore ( f a ) done ; let t2 = Sys . time ( ) in ( t2 . - t1 ) let warmup ( ) = let x = ref 0 in let rec go start = if Sys . time ( ) . - start < 1 . then begin for i = 0 to 10000 do x := ! x + i done ; go start end in go ( Sys . time ... |
let _ = Rng . reseed ( Cstruct . of_string " abcd " ) |
let sizes = [ 16 ; 64 ; 256 ; 1024 ; 8192 ] |
let burn f n = let cs = Rng . generate n in let ( t1 , i1 ) = let rec loop it = let t = Time . time ~ n : it f cs in if t > 0 . 2 then ( t , it ) else loop ( it * 10 ) in loop 10 in let iters = int_of_float ( float i1 . * burn_period . / t1 ) in let time = Time . time ~ n : iters f cs in ( iters , time , float ( n * it... |
let mb = 1024 . . * 1024 . |
let throughput title f = Printf . printf " \ n * [ % s ] \ n " %! title ; sizes |> List . iter @@ fun size -> Gc . full_major ( ) ; let ( iters , time , bw ) = burn f size in Printf . printf " % 5d : % 04 . f MB / s ( % d iters in . % 03f s ) \ n " %! size ( bw . / mb ) iters time |
let bm name f = ( name , fun ( ) -> f name ) |
let benchmarks = [ bm " aes - 128 - ecb " ( fun name -> let key = AES . ECB . of_secret ( Rng . generate 16 ) in throughput name ( fun cs -> AES . ECB . encrypt ~ key cs ) ) ; bm " aes - 128 - cbc - e " ( fun name -> let key = AES . CBC . of_secret ( Rng . generate 16 ) and iv = Rng . generate 16 in throughput name ( f... |
let help ( ) = Printf . printf " available benchmarks :\ n " ; List . iter ( fun ( n , _ ) -> Printf . printf " % s " n ) benchmarks ; Printf . printf " \ n " %! |
let runv fs = Format . printf " accel : % a \ n " %! ( fun ppf -> List . iter @@ fun x -> Format . fprintf ppf " % s " @@ match x with ` XOR -> " XOR " | ` AES -> " AES " | ` GHASH -> " GHASH " ) Nocrypto . Cipher_block . accelerated ; Time . warmup ( ) ; List . iter ( fun f -> f ( ) ) fs |
let _ = match Array . to_list Sys . argv with | _ ( :: _ :: _ as args ) -> begin try let fs = args |> List . map @@ fun n -> snd ( benchmarks |> List . find @@ fun ( n1 , _ ) -> n = n1 ) in runv fs with Not_found -> help ( ) end | _ -> help ( ) |
let time_fn msg fn = let start = Sys . time ( ) in let res = fn ( ) in let stop = Sys . time ( ) in Printf . printf " % 6 . 2f % s \ n " ( stop . - start ) msg ; flush stdout ; res |
let rec repeat n fn ( ) = if n <= 1 then fn ( ) else ( ignore ( fn ( ) ) ; repeat ( n - 1 ) fn ( ) ) |
let raw_block_cipher cipher niter ( ) = let msg = String . create cipher # blocksize in for i = 1 to niter do cipher # transform msg 0 msg 0 done |
let raw_stream_cipher cipher niter blocksize ( ) = let msg = String . create blocksize in for i = 1 to niter do cipher # transform msg 0 msg 0 blocksize done |
let transform tr niter blocksize ( ) = let msg = String . create blocksize in for i = 1 to niter do tr # put_substring msg 0 blocksize ; ignore ( tr # get_substring ) done |
let hash h niter blocksize ( ) = let msg = String . create blocksize in for i = 1 to niter do h # add_substring msg 0 blocksize done ; ignore ( h # result ) |
let _ = time_fn " Raw AES 128 , 16_000_000 bytes " ( raw_block_cipher ( new Block . aes_encrypt " 0123456789ABCDEF " ) 1000000 ) ; time_fn " Raw AES 192 , 16_000_000 bytes " ( raw_block_cipher ( new Block . aes_encrypt " 0123456789ABCDEF01234567 " ) 1000000 ) ; time_fn " Raw AES 256 , 16_000_000 bytes " ( raw_block_cip... |
let run_test ~ fill_before_upon ~ no_ivars ~ spawn_factor = let spawn = let spawns = List . range 0 spawn_factor in fun i -> List . iter spawns ~ f ( : fun _ -> upon ( Ivar . read i ) Fn . ignore ) in let finished = Ivar . create ( ) in let rec loop n = if n > 0 then ( let i = Ivar . create ( ) in if fill_before_upon t... |
let ( ) = let no_ivars = int_of_string ( Sys . get_argv ( ) ) . ( 1 ) in let spawn_factor = int_of_string ( Sys . get_argv ( ) ) . ( 2 ) in if spawn_factor >= 20 then failwith " spawn_factor must be less than 20 " ; let fill_before_upon = match ( Sys . get_argv ( ) ) . ( 3 ) with | " fill " -> true | " upon " -> false ... |
let levenshtein_distance s t cutoff = let m = String . length s and n = String . length t in if cutoff = 0 || abs ( m - n ) >= cutoff then None else let d = Array . make_matrix ~ dimx ( : m + 1 ) ~ dimy ( : n + 1 ) 0 in for i = 0 to m do d . ( i ) . ( 0 ) <- i done ; for j = 0 to n do d . ( 0 ) . ( j ) <- j done ; let ... |
let spellcheck names name = let cutoff = match String . length name with | 1 | 2 -> 0 | 3 | 4 -> 1 | 5 | 6 -> 2 | _ -> 3 in let _ , suggestions = List . fold_left names ~ init ( : Int . max_int , [ ] ) ~ f ( : fun ( ( best_distance , names_at_best_distance ) as acc ) registered_name -> match levenshtein_distance name r... |
let spill_env = ref ( Reg . Map . empty : Reg . t Reg . Map . t ) |
let spill_reg r = try Reg . Map . find r ! spill_env with Not_found -> let spill_r = Reg . create r . typ in spill_r . spill <- true ; if not ( Reg . anonymous r ) then spill_r . raw_name <- r . raw_name ; spill_env := Reg . Map . add r spill_r ! spill_env ; spill_r |
let use_date = ref ( Reg . Map . empty : int Reg . Map . t ) |
let current_date = ref 0 |
let record_use regv = for i = 0 to Array . length regv - 1 do let r = regv . ( i ) in let prev_date = try Reg . Map . find r ! use_date with Not_found -> 0 in if ! current_date > prev_date then use_date := Reg . Map . add r ! current_date ! use_date done |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.