<commit_before>USING: byte-arrays calendar kernel math memory namespaces parser
random sequences threads tools.profiler.sampling
tools.profiler.sampling.private tools.test ;
IN: tools.profiler.sampling.tests

! Make sure the profiler doesn't blow up the VM
TUPLE: boom ;
{ } [ 10 [ [ ] profile ] times ] unit-test
[ 10 [ [ boom new throw ] profile ] times ] [ boom? ] must-fail-with
{ } [ 10 [ [ 100 [ 1000 random (byte-array) drop ] times gc ] profile ] times ] unit-test
{ } [ 10 [ [ 100 [ 1000 random (byte-array) drop ] times compact-gc ] profile ] times ] unit-test
{ } [ 2 [ [ 1 seconds sleep ] profile ] times ] unit-test

{ } [ [ 300,000 iota [ sq sq sq ] map drop ] profile flat profile. ] unit-test
{ } [ [ 300,000 iota [ sq sq sq ] map drop ] profile top-down profile. ] unit-test

f raw-profile-data set-global
gc

{ t 0 } [
    ! Seed the samples data
    [ "resource:basis/tools/memory/memory.factor" run-file ] profile
    (get-samples) length 0 >
    ! Should clear it
    gc [ ] profile (get-samples) length
] unit-test
<commit_msg>tools.profiler.sampling.tests: attempt to fix the unit test that fails on x86.32 sometimes<commit_after>USING: byte-arrays calendar kernel math memory namespaces parser
random sequences threads tools.profiler.sampling
tools.profiler.sampling.private tools.test ;
IN: tools.profiler.sampling.tests

! Make sure the profiler doesn't blow up the VM
TUPLE: boom ;
{ } [ 10 [ [ ] profile ] times ] unit-test
[ 10 [ [ boom new throw ] profile ] times ] [ boom? ] must-fail-with
{ } [ 10 [ [ 100 [ 1000 random (byte-array) drop ] times gc ] profile ] times ] unit-test
{ } [ 10 [ [ 100 [ 1000 random (byte-array) drop ] times compact-gc ] profile ] times ] unit-test
{ } [ 2 [ [ 1 seconds sleep ] profile ] times ] unit-test

{ } [ [ 300,000 iota [ sq sq sq ] map drop ] profile flat profile. ] unit-test
{ } [ [ 300,000 iota [ sq sq sq ] map drop ] profile top-down profile. ] unit-test

f raw-profile-data set-global
gc

{ t t } [
    ! Seed the samples data
    [ "resource:basis/tools/memory/memory.factor" run-file ] profile
    (get-samples) length 0 >
    ! On x86.64, [ ] profile doesn't generate any samples at all
    ! because it runs so quickly. On x86.32, one spurious sample is
    ! sometimes generated for some unknown reason.
    gc [ ] profile (get-samples) length 1 <=
] unit-test

{'fraction_non_alphanumeric': 0.11870196413321947, 'fraction_numerical': 0.037574722459436376, 'mean_word_length': 3.252268602540835, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2646123', 'n_tokens_mistral': 818, 'n_tokens_neox': 727, 'n_words': 263}