• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Custom IC SKILL
  3. nthelem( list ) vs cadr( list )

Stats

  • Locked Locked
  • Replies 1
  • Subscribers 143
  • Views 15945
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

nthelem( list ) vs cadr( list )

liorscotland
liorscotland over 7 years ago

Hello all.

If one uses nthelem( 2 <input list ) or cadr( list elem ), the output would be identical.

Is there any performance/ other reason to prefer one over the other, on SKILL 6.1.7 and above?

Thanks

  • Cancel
Parents
  • Andrew Beckett
    Andrew Beckett over 7 years ago

    Hi Lior,

    I wouldn't worry about it. I just profiled running each of nthelem(2 lst) nth(1 lst) and cadr(lst) 100 million times, and from two experiments of each I saw:

    cadr: 12.12 12.12
    nthelem: 13.11 13.28
    nth: 13.00 13.21

    So if it's only taking 12 or 13 seconds for 100 million operations, that's something that I'd class as over-optimising your code! I'd go for style over (minor) performance benefits here - so whatever makes most sense to you. In practice I rarely use nth or nthelem because it's unusual for me to want to get a fixed element from a list unless it's short, otherwise I'd iterate over the list - odd occasions when you have a short list with more than 4 items I might, but otherwise I tend to use car, cadr, caddr or cadddr - it's a matter of typing a little less (not much though).

    So pick whichever works for you.

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • Andrew Beckett
    Andrew Beckett over 7 years ago

    Hi Lior,

    I wouldn't worry about it. I just profiled running each of nthelem(2 lst) nth(1 lst) and cadr(lst) 100 million times, and from two experiments of each I saw:

    cadr: 12.12 12.12
    nthelem: 13.11 13.28
    nth: 13.00 13.21

    So if it's only taking 12 or 13 seconds for 100 million operations, that's something that I'd class as over-optimising your code! I'd go for style over (minor) performance benefits here - so whatever makes most sense to you. In practice I rarely use nth or nthelem because it's unusual for me to want to get a fixed element from a list unless it's short, otherwise I'd iterate over the list - odd occasions when you have a short list with more than 4 items I might, but otherwise I tend to use car, cadr, caddr or cadddr - it's a matter of typing a little less (not much though).

    So pick whichever works for you.

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Children
No Data

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information