## DEV Community is a community of 601,801 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

loading... # Testing Jasmine Speed bob.js Updated on ・2 min read

I was told, "a single it within a describe is an order or magnitude faster than multiple its within the same describe." I thanked the individual and walked away. Then, what he said to me sank in ... and, to say I was dubious would be an understatement.

This was something I had to test ...

The code supporting this article is HERE.

## Initial Testing

Initial Results:

Type Random Run Result
Multiple IT within DESCRIBE TRUE 4.294s
Multiple IT within DESCRIBE FALSE 4.375s
Single IT within many DESCRIBES TRUE 8.426s
Single IT within many DESCRIBES FALSE 8.380s

The multiple IT within DESCRIBE code looks like this ...

``````describe('speed testing', function() {
const maxRuns = 10000;

function multipleIt() {
it('something simple', function() {
expect(true).toEqual(true);
});
}

describe('multiple its per describe', function() {
describe('wrapper', function() {
for (let i = 0, len = maxRuns; i < len; i++) {
multipleIt();
}
});
});
});
``````

... and the single IT within many DESCRIBES code looks like this ...

``````describe('speed testing', function() {
const maxRuns = 10000;

function singleIt() {
describe('single it run', function() {
it('something simple', function() {
expect(true).toEqual(true);
});
});
}

describe('single it per describe', function() {
for (let i = 0, len = maxRuns; i < len; i++) {
singleIt();
}
});
});
``````

Then, I got to thinking that maybe the for-loop in the tests above was in some way impacting the test runs. So, I reworked the two test suites. I also added in testing that covered multiple nested DESCRIBE ...

## Non-Iterative Testing

Number of Tests Type Random Run Result
1,000 Multiple DESCRIBE TRUE 5.182s
1,000 Multiple DESCRIBE FALSE 5.109s
1,000 Multiple IT within DESCRIBE TRUE 0.534s
1,000 Multiple IT within DESCRIBE FALSE 0.545s
1,000 Single IT within many DESCRIBES TRUE 0.943s
1,000 Single IT within many DESCRIBES FALSE 0.959s

The deeply nested DESCRIBE code looks like this ...

``````describe('wrapper 1', function() {
describe('wrapper 2', function() {
describe('wrapper 3', function() {
describe('wrapper 4', function() {
describe('wrapper 5', function() {
describe('wrapper 6', function() {
describe('wrapper 7', function() {
describe('wrapper 8', function() {
describe('wrapper 9', function() {
describe('wrapper 10', function() {
it('something simple', function() {
expect(true).toEqual(true);
});
});
});
});
});
});
});
});
});
});
});
``````

The multiple IT within DESCRIBE code looks like this ...

``````describe('speed testing', function() {
describe('multiple its per describe 1000', function() {
describe('wrapper', function() {
it('something simple', function() {
expect(true).toEqual(true);
});

// ... 998 ITS like the one above (or below)

it('something simple', function() {
expect(true).toEqual(true);
});

});
});
});
``````

... and the single IT within many DESCRIBES code looks like ...

``````describe('speed testing', function() {
describe('single it per describe 1000', function() {
describe('single it run', function() {
it('something simple', function() {
expect(true).toEqual(true);
});
});

// ... 998 DESCRIBES like the one above (or below)

describe('single it run', function() {
it('something simple', function() {
expect(true).toEqual(true);
});
});

});
});
``````

## Conclusion

Common sense won out ...

The data here supports what common sense told me; that having multiple ITS within a single DESCRIBE is inherently faster within Jasmine than having a single IT within many DESCRIBE statements.

Additionally, the slowest of the types of tests are the deeply nested DESCRIBE.

## Discussion (0)
{"ft_lang_label":"__label__en","ft_lang_prob":0.71619385,"math_prob":0.85061014,"size":3543,"snap":"2021-04-2021-17","text_gpt3_token_len":891,"char_repetition_ratio":0.24809268,"word_repetition_ratio":0.30326295,"special_character_ratio":0.32119673,"punctuation_ratio":0.23556231,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9563149,"pos_list":[0,1,2,3,4,5,6],"im_url_duplicate_count":[null,3,null,8,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-04-13T14:26:27Z\",\"WARC-Record-ID\":\"<urn:uuid:a575f766-bff7-4e9a-8798-4e8993cc9401>\",\"Content-Length\":\"125069\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:2bd52e29-ac1c-4920-9307-a0c4fdb37b9b>\",\"WARC-Concurrent-To\":\"<urn:uuid:f4da8641-3399-456e-8e20-44e034f08025>\",\"WARC-IP-Address\":\"151.101.201.194\",\"WARC-Target-URI\":\"https://practicaldev-herokuapp-com.global.ssl.fastly.net/rfornal/testing-jasmine-speed-38e9\",\"WARC-Payload-Digest\":\"sha1:XFWY36HHUD52LEG2OVVOMM73VNGCG4DT\",\"WARC-Block-Digest\":\"sha1:LJACJEAI3JOCZHD4WKZXQCA565CCS3ZW\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-17/CC-MAIN-2021-17_segments_1618038072366.31_warc_CC-MAIN-20210413122252-20210413152252-00363.warc.gz\"}"}