1. 12
  1.  

  2. 1

    Why is the non-parallelized rust program faster than the c program?

    1. 2

      The rust version seems to pick only the first best key rotor, but the C version keeps track of several. Unless I’ve misread the code?

      C:

      for(elem = base; elem != NULL; elem = elem->next){
          currentkey = &(elem->key);
          ind2 = currentkey->indicator[1];
          ind3 = currentkey->indicator[2];
          for(set2=0; set2<26;set2++){
              for(set3=0; set3<26;set3++){
      

      That’s three loops.

      rust:

      let (_, msg, key, ring) = iproduct!(key_offset..(key_offset + 676), 0..676)
          .collect::<Vec<_>>()
          .par_iter()
          .map(|&(key_index, ring_index)| {
      

      That’s the same code. The two inner loops are folded together, but I don’t see the iteration over the other keys, the outer loop above.

      The rust code uses max_by_key in the top loop where the C code has base = nbest_add(base,&key,score);.