string concat vs array push then join per symbol

JavaScript performance comparison

Test case created by Krassimir

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var s ="'<select-stmt> ::= SELECT <select-clause>                   FROM <tablename>                   ( USING CONSISTENCY <consistency-level> )?                   ( WHERE <where-clause> )?                   ( ORDER BY <order-by> )?                   ( LIMIT <integer> )?  <select-clause> ::= <column-list>                   | COUNT '(' ( '*' | '1' ) ')'  <column-list> ::= <selected_id> ( ',' <selected_id> )*                 | '*'  <selected_id> ::= <identifier>                 | WRITETIME '(' <identifier> ')'                 | TTL '(' <identifier> ')'  <where-clause> ::= <relation> ( 'AND' <relation> )*  <relation> ::= <identifier> ('=' | '<' | '>' | '<=' | '>=') <term>              | <identifier> IN '(' <term> ( ',' <term>)* ')'              | TOKEN '(' <identifier> ')' ('=' | '<' | '>' | '<=' | '>=') (<term> | TOKEN '( <term> ')' )  <order-by> ::= <ordering> ( ',' <odering> )* <ordering> ::= <identifer> ( ASC | DESC )?  Sample:  SELECT name, occupation FROM users WHERE userid IN (199, 200, 207);  SELECT time, value FROM events WHERE event_type = 'myEvent'   AND time > 2011-02-03   AND time <= 2012-01-01  SELECT COUNT(*) FROM users;  The SELECT statements reads one or more columns for one or more rows in a table. It returns a result-set of rows, where each row contains the collection of columns corresponding to the query.  <select-clause>  The <select-clause> determines which columns needs to be queried and returned in the result-set. It consists of either the comma-separated list of column names to query, or the wildcard character (*) to select all the columns defined for the table.  In addition to selecting columns, the WRITETIME (resp. TTL) function allows to select the timestamp of when the column was inserted (resp. the time to live (in seconds) for the column (or null if the column has no expiration set)).  The COUNT keyword can be used with parenthesis enclosing *. If so, the query will return a single result: the number of rows matching the query. Note that COUNT(1) is supported as an alias.  <where-clause>  The <where-clause> specifies which rows must be queried. It is composed of relations on the columns that are part of the PRIMARY KEY and/or have a secondary index defined on them.  Not all relations are allowed in a query. For instance, non-equal relations (where IN is considered as an equal relation) on a partition key is only supported if the partitioner for the keyspace is an ordered one. Moreover, for a given partition key, the clustering keys induce an ordering of rows and relations on them is restricted to the relations that allow to select a contiguous (for the ordering) set of rows. For instance, given  CREATE TABLE posts (     userid text,     blog_title text,     posted_at timestamp,     entry_title text,     content text,     category int,     PRIMARY KEY (userid, blog_title, posted_at) ) The following query is allowed: SELECT entry_title, content FROM posts WHERE userid='john doe' AND blog_title='John's Blog' AND posted_at >= 2012-01-01 AND posted_at < 2012-01-31 But the following one is not, as it does not select a contiguous set of rows (and we suppose no secondary indexes are set):  // Needs a blog_title to be set to select ranges of posted_at SELECT entry_title, content FROM posts WHERE userid='john doe' AND posted_at >= 2012-01-01 AND posted_at < 2012-01-31 When specifying relations, the TOKEN function can be used on the PARTITION KEY column to query. In that case, rows will be selected based on the token of their PARTITION_KEY rather than on the value (note that the token of a key depends on the partitioner in use, and that in particular the RandomPartitioner won’t yeld a meaningful order). Example:  SELECT * FROM posts WHERE token(userid) > token('tom') AND token(userid) < token('bob') <order-by>  The ORDER BY option allows to select the order of the returned results. It takes as argument a list of column names along with the order for the column (ASC for ascendant and DESC for descendant, omitting the order being equivalent to ASC). Currently the possible orderings are limited (which depends on the table CLUSTERING ORDER):  if the table has been defined without any specific CLUSTERING ORDER, then then allowed orderings are the order induced by the clustering key and the reverse of that one. otherwise, the orderings allowed are the order of the CLUSTERING ORDER option and the reversed one. Other options  The consistency level of a query can be set as for data manipulation statements using the USING CONSISTENCY keywords.  The LIMIT option to a SELECT statement limits the number of rows returned by a query. LIMIT defaults to 10,000 when left unset.  Data Types  CQL supports a rich set of native data types for columns defined in a table. On top of those native types, users can also provide custom types (through a JAVA class extending AbstractType loadable by Cassandra). The syntax of types is thus:  <type> ::= <native_type>          | <string>       // Used for custom types. The fully-qualified name of a JAVA class  <native_type> ::= ascii                 | bigint                 | blob                 | boolean                 | counter                 | decimal                 | double                 | float                 | int                 | text                 | timestamp                 | timeuuid                 | uuid                 | varchar                 | varint Note that the native types are keywords and as such are case-insensitive. They are however not reserved ones.'";

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
concat
var r = "",
    i, l = s.length;
for (i = 0; i < l; i++) {
  r += s.charAt(i);
}
pending…
join
var r = [],
    i, l = s.length;
for (i = 0; i < l; i++) {
  r.push(s.charAt(i));
}
r = r.join("");
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL.

0 Comments