Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8999319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:09:54+00:00 2026-06-16T00:09:54+00:00

I am working on optimizing a piece of software and the most expensive lines

  • 0

I am working on optimizing a piece of software and the most expensive lines are the text processing lines of code. By taking apart the program and commenting certain sections out, I have found out that a little argument in an if-statement is causing most of the bottleneck in the program. In the statement it asks if

allele1 %in% rownames(seqMat)

is true, and if so the statements that follow will be called. This if statement is looped thousands of times and causes the program to slow down significantly. My question is, how can that statement be changed to help speed up the program?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:09:54+00:00Added an answer on June 16, 2026 at 12:09 am

    You could call %in% only once for all your alleles and store its output for reuse inside the loop. Here is a proof of concept:

    a <- sample(1:1000, 100000, replace = TRUE)
    b <- -1000:1000
    
    system.time({
        stored <- a %in% b
        for (i in seq_along(a))
            stored[i]
    }) 
    #    user  system elapsed 
    #   0.056   0.001   0.056 
    
    system.time({
        for (i in seq_along(a))
            a[i] %in% b
    })
    #    user  system elapsed 
    #   3.634   0.374   3.957
    

    Also, Hadley’s suggestion of using any and == is not that big of an improvement:

    system.time({
        for (i in seq_along(a))
            any(a[i] == b)
    })
    #    user  system elapsed 
    #   1.661   0.164   1.835 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on optimizing the performance of my TableViews, and was wondering how expensive
Tonight I've been taking a look at some code I've been working on over
I'm working with optimizing a software and wants to measure the performance. So I
I've been working on optimizing my project's DB calls and I noticed a significant
I'm student working on optimizing GCC for multi-core processor. I tried going through the
I am working on optimizing a query which is used very frequently on our
I am working with optimizing a single C object file with regards on the
I’m working on optimizing some of my queries and I have a query that
I am working on optimizing site load speed for a few moderately high traffic
I'm working on optimizing an application . I found that i need to optimize

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.