# Optimizing dinucleotides count in a DNA sequence type \`LongDNA\`

**URL:** <https://discourse.julialang.org/t/optimizing-dinucleotides-count-in-a-dna-sequence-type-longdna/101583>\
**Category:** Performance\
**Tags:** question, performance, strings, biology\
**Created:** [July 13, 2023, 4:51pm UTC](https://discourse.julialang.org/t/optimizing-dinucleotides-count-in-a-dna-sequence-type-longdna/101583 "2023-07-13T16:51:55Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [July 13, 2023, 6:29pm UTC](https://discourse.julialang.org/t/optimizing-dinucleotides-count-in-a-dna-sequence-type-longdna/101583/4 "2023-07-13T18:29:02Z")

</div>

It allocates a lot because it does two copies of the list when taking slices. I wrote it that way for simplicity, but a better way to write it would be the following:

```julia
a = @view seq[begin:end-1]
b = @view seq[begin+1:end]
countmap(zip(a, b))

```

This should not allocate as much.

---

_[View the full topic](https://discourse.julialang.org/t/optimizing-dinucleotides-count-in-a-dna-sequence-type-longdna/101583)._
